There is a new revision of this tutorial available for Ubuntu 14.04 LTS (Trusty Tahr).

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

Lighttpd is a secure, fast, standards-compliant web server designed for speed-critical environments. This tutorial shows how you can install Lighttpd on an Ubuntu 12.04 server with PHP5 support (through PHP-FPM) and MySQL support. PHP-FPM (FastCGI Process Manager) is an alternative PHP FastCGI implementation with some additional features useful for sites of any size, especially busier sites. I use PHP-FPM in this tutorial instead of Lighttpd's spawn-fcgi.


1 Preliminary Note

In this tutorial, I use the hostname with the IP address These settings might differ for you, so you have to replace them where appropriate.

I'm running all the steps in this tutorial with root privileges, so make sure you're logged in as root:

sudo su


2 Installing MySQL 5

First we install MySQL 5 like this:

apt-get install mysql-server mysql-client

You will be asked to provide a password for the MySQL root user - this password is valid for the user [email protected] as well as [email protected], so we don't have to specify a MySQL root password manually later on:

New password for the MySQL "root" user: <-- yourrootsqlpassword
Repeat password for the MySQL "root" user: <-- yourrootsqlpassword


3 Installing Lighttpd

Lighttpd is available as an Ubuntu package, therefore we can install it like this:

apt-get install lighttpd

Now direct your browser to, and you should see the Lighttpd placeholder page:

Lighttpd's default document root is /var/www on Ubuntu, and the configuration file is /etc/lighttpd/lighttpd.conf. Additional configurations are stored in files in the /etc/lighttpd/conf-available directory - these configurations can be enabled with the lighttpd-enable-mod command which creates a symlink from the /etc/lighttpd/conf-enabled directory to the appropriate configuration file in /etc/lighttpd/conf-available. You can disable configurations with the lighttpd-disable-mod command.


4 Installing PHP5

We can make PHP5 work in Lighttpd through PHP-FPM which we install like this:

apt-get install php5-fpm php5

PHP-FPM is a daemon process (with the init script /etc/init.d/php5-fpm) that runs a FastCGI server on port 9000.


5 Configuring Lighttpd And PHP5

To enable PHP5 in Lighttpd, we must modify /etc/php5/fpm/php.ini and uncomment the line cgi.fix_pathinfo=1:

vi /etc/php5/fpm/php.ini

; cgi.fix_pathinfo provides *real* PATH_INFO/PATH_TRANSLATED support for CGI.  PHP's
; previous behaviour was to set PATH_TRANSLATED to SCRIPT_FILENAME, and to not grok
; what PATH_INFO is.  For more information on PATH_INFO, see the cgi specs.  Setting
; this to 1 will cause PHP CGI to fix its paths to conform to the spec.  A setting
; of zero causes PHP to behave as before.  Default is 1.  You should fix your scripts

The Lighttpd configuration file for PHP /etc/lighttpd/conf-available/15-fastcgi-php.conf is suitable for use with spawn-fcgi, however, we want to use PHP-FPM, therefore we create a backup of the file (named 15-fastcgi-php-spawnfcgi.conf) and modify 15-fastcgi-php.conf as follows:

cd /etc/lighttpd/conf-available/
cp 15-fastcgi-php.conf 15-fastcgi-php-spawnfcgi.conf
vi 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" =>
                "host" => "",
                "port" => "9000",
                "broken-scriptfilename" => "enable"

To enable the fastcgi configuration, run the following commands:

lighttpd-enable-mod fastcgi
lighttpd-enable-mod fastcgi-php

This creates the symlinks /etc/lighttpd/conf-enabled/10-fastcgi.conf which points to /etc/lighttpd/conf-available/10-fastcgi.conf and /etc/lighttpd/conf-enabled/15-fastcgi-php.conf which points to /etc/lighttpd/conf-available/15-fastcgi-php.conf:

ls -l /etc/lighttpd/conf-enabled

[email protected]:/etc/lighttpd/conf-available# ls -l /etc/lighttpd/conf-enabled
total 0
lrwxrwxrwx 1 root root 33 May 15 19:50 10-fastcgi.conf -> ../conf-available/10-fastcgi.conf
lrwxrwxrwx 1 root root 41 May 15 19:50 15-fastcgi-php.conf -> ../conf-available/15-fastcgi-php.conf
[email protected]:/etc/lighttpd/conf-available#

Then we reload Lighttpd:

/etc/init.d/lighttpd force-reload

Share this page:

5 Comment(s)

Add comment


From: Anonymous

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


From: Anonymous

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

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

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: Frank Carew

Hi, If you recieve the following error or you start having 503 errors: 

backend died; we'll disable it for 1 seconds and send the request to another backend instead: reconnects: 0 load: 1 


You will need to comment out the following lines in /etc/php5/fpm/pool.d/www.conf 




;listen.owner = www-data

; = www-data

;listen.mode = 0660





listen.owner = www-data = www-data

listen.mode = 0660