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

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


Now we call that file in a browser (e.g.

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 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


9 Making PHP-FPM Use A Unix Socket

By default PHP-FPM is listening on port 9000 on 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 =
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

## 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

Share this page:

5 Comment(s)

Add comment


From: Anonymous at: 2012-12-04 19:26:11

Nice How-to but, looks like we are missing something like "apt-get install php5-cgi" to have the full thing working.


From: Anonymous at: 2012-12-05 19:41:05

Hello, thank to all for your tuto

I'm french and don't understand this:

 uncomment the line cgi.fix_pathinfo=1

in french there is no translation right for the word "uncomment"

what to do, delete the line or change 1 into O

thank to answer this for me

From: Anonymous at: 2012-12-26 05:29:40

This is all fine and dandy, except that by default (on Ubuntu 12.04) it's configured to listen on a socket (/var/run/php5-fpm.sock) rather than on  Spent a bunch of time cursing all the gods that ever lived trying to figure this one out ;)

From: Anonymous at: 2012-12-26 05:39:15

Assuming the default php5-fpm configuration that comes with Ubuntu 12.04, you can make it work with the following fastcgi configuration:


fastcgi.server += ( ".php" =>
                "socket" => "/var/run/php5-fpm.sock",
                "broken-scriptfilename" => "enable"


From: Anonymous at: 2012-10-19 05:59:43

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:
2012-10-19 13:44:40: (mod_fastcgi.c.1732) connect failed: Permission denied on tcp:
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:
2012-10-19 13:44:52: (mod_fastcgi.c.1732) connect failed: Permission denied on tcp:
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:
2012-10-19 13:46:24: (mod_fastcgi.c.1732) connect failed: Permission denied on tcp:
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: