Installing Lighttpd With PHP5 (PHP-FPM) And MySQL Support On Ubuntu 12.04 - Page 2

Want to support HowtoForge? Become a subscriber!
 
Submitted by falko (Contact Author) (Forums) on Thu, 2012-05-24 17:46. ::

6 Testing PHP5 / Getting Details About Your PHP5 Installation

The document root of the default web site is /var/www. We will now create a small PHP file (info.php) in that directory and call it in a browser. The file will display lots of useful details about our PHP installation, such as the installed PHP version.

vi /var/www/info.php

<?php
phpinfo();
?>

Now we call that file in a browser (e.g. http://192.168.0.100/info.php):

As you see, PHP5 is working, and it's working through FPM/FastCGI, as shown in the Server API line. If you scroll further down, you will see all modules that are already enabled in PHP5. MySQL is not listed there which means we don't have MySQL support in PHP5 yet.

 

7 Getting MySQL Support In PHP5

To get MySQL support in PHP, we can install the php5-mysql package. It's a good idea to install some other PHP5 modules as well as you might need them for your applications. You can search for available PHP5 modules like this:

apt-cache search php5

Pick the ones you need and install them like this:

apt-get install php5-mysql php5-curl php5-gd php5-intl php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-ming php5-ps php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl

Xcache is a free and open PHP opcode cacher for caching and optimizing PHP intermediate code. It's similar to other PHP opcode cachers, such as eAccelerator and APC. It is strongly recommended to have one of these installed to speed up your PHP page.

Xcache can be installed as follows:

apt-get install php5-xcache

Now reload PHP-FPM:

/etc/init.d/php5-fpm reload

Now reload http://192.168.0.100/info.php in your browser and scroll down to the modules section again. You should now find lots of new modules there, including the MySQL module:

 

8 phpMyAdmin

phpMyAdmin is a web interface through which you can manage your MySQL databases. It's a good idea to install it:

apt-get install phpmyadmin

You will see the following questions:

Web server to reconfigure automatically: <-- lighttpd
Configure database for phpmyadmin with dbconfig-common? <-- No

Afterwards, you can access phpMyAdmin under http://192.168.0.100/phpmyadmin/:

 

9 Making PHP-FPM Use A Unix Socket

By default PHP-FPM is listening on port 9000 on 127.0.0.1. It is also possible to make PHP-FPM use a Unix socket which avoids the TCP overhead. To do this, open /etc/php5/fpm/pool.d/www.conf...

vi /etc/php5/fpm/pool.d/www.conf

... and make the listen line look as follows:

[...]
;listen = 127.0.0.1:9000
listen = /tmp/php5-fpm.sock
[...]

Then reload PHP-FPM:

/etc/init.d/php5-fpm reload

Next open Lighttpd's PHP configuration file /etc/lighttpd/conf-available/15-fastcgi-php.conf and replace the host and port lines with "socket" => "/tmp/php5-fpm.sock":

vi /etc/lighttpd/conf-available/15-fastcgi-php.conf

# /usr/share/doc/lighttpd-doc/fastcgi.txt.gz
# http://redmine.lighttpd.net/projects/lighttpd/wiki/Docs:ConfigurationOptions#mod_fastcgi-fastcgi

## Start an FastCGI server for php (needs the php5-cgi package)
fastcgi.server += ( ".php" =>
        ((
                "socket" => "/tmp/php5-fpm.sock",
                "broken-scriptfilename" => "enable"
        ))
)

Finally reload Lighttpd:

/etc/init.d/lighttpd force-reload

 

10 Links


Please do not use the comment function to ask for help! If you need help, please use our forum.
Comments will be published after administrator approval.
Submitted by Anonymous (not registered) on Fri, 2012-10-19 06:59.

error after installing lighttpd and php-fpm

 

tailf /var/log/lighttpd/error.log
2012-10-19 13:36:53: (mod_fastcgi.c.2829) fcgi-server re-enabled: tcp:127.0.0.1:9000
2012-10-19 13:44:40: (mod_fastcgi.c.1732) connect failed: Permission denied on tcp:127.0.0.1:9000
2012-10-19 13:44:40: (mod_fastcgi.c.3002) backend died; we'll disable it for 1 seconds and send the request to another backend instead: reconnects: 0 load: 1
2012-10-19 13:44:42: (mod_fastcgi.c.2829) fcgi-server re-enabled: tcp:127.0.0.1:9000
2012-10-19 13:44:52: (mod_fastcgi.c.1732) connect failed: Permission denied on tcp:127.0.0.1:9000
2012-10-19 13:44:52: (mod_fastcgi.c.3002) backend died; we'll disable it for 1 seconds and send the request to another backend instead: reconnects: 0 load: 1
2012-10-19 13:44:54: (mod_fastcgi.c.2829) fcgi-server re-enabled: tcp:127.0.0.1:9000
2012-10-19 13:46:24: (mod_fastcgi.c.1732) connect failed: Permission denied on tcp:127.0.0.1:9000
2012-10-19 13:46:24: (mod_fastcgi.c.3002) backend died; we'll disable it for 1 seconds and send the request to another backend instead: reconnects: 0 load: 1
2012-10-19 13:46:26: (mod_fastcgi.c.2829) fcgi-server re-enabled: tcp:127.0.0.1:9000