Lighttpd - Install and configuration for Drupal


Lighttpd supports PHP through both CGI and FastCGI. As the name suggests, FastCGI is preferable.

FastCGI is a language independent, scalable, open extension to CGI that provides high performance without the limitations of server specific APIs.

FastCGI provides better scalability and performance. Instead of creating a new process (the CGI program) for every request, FastCGI uses a single persistent process which handles many requests over its lifetime.


On ubuntu (and Debian):
$ sudo apt-get install lighttpd-mod-magnet php5-cgi php5-cli php5-mysql mysql-server php5-gd

You need to edit 2 files,
lighttpd.conf and php.ini,
and download 1 file named drupal.lua.

$ wget
$ sudo cp drupal.lua /etc/lighttpd/

Change the binary path for php:

$ sudo vim /etc/php5/cgi/php.ini
cgi.fix_pathinfo = 1
and edit
memory_limit = 32M

$ sudo vim /etc/lighttpd/lighttpd.conf

and add the following configuration:

fastcgi.server = (
                    ".php" => ((
                    "bin-path" => "/usr/bin/php-cgi",
                    "socket" => "/tmp/php.socket"

$HTTP["url"] =~ "^/drupal-5.1" {
    # we only need index.php here.
    index-file.names = ( "index.php" )
    # for clean urls
    magnet.attract-physical-path-to = ( "/etc/lighttpd/drupal.lua" )

Enable the required modules in terminal:

$ sudo lighty-enable-mod fastcgi && lighty-enable-mod magnet

Setting up your work dir (for a development environment )
$ sudo vim /etc/lighttpd/lighttpd.conf
server.document-root       = "/var/www/"
server.document-root       = "/home/user/www/"

restart the server:
$ sudo /etc/init.d/lighttpd force-reload

There you go, fly light! ;)

Clean urls and lua
mod_magnet depends on lua5.1+
For history, see

make a file named drupal.lua, and add following configuration(drupal.lua can be placed anywhere on the server, but be sure to assign correct path in both drupal.lua and under the configuration snippet under lighttpd.conf). See
and download the drupal.lua that darix have made.

If your drupal directory is named something other than drupal-5.1 eg. HEAD you will need to edit the drupal.lua file and lighttpd.conf:
In lighttpd.conf you change
$HTTP["url"] =~ "^/drupal-5.1"
$HTTP["url"] =~ "^/HEAD"
and in drupal.lua you need to change the local prefix to:
local prefix = '/HEAD'

We currently do not support multiple installations for clean url's. But we hope to have this fixed in the near future.

Memory limit Keep in mind the '500 error' you will get when your memory limit is set too low. 8MB is default (or at least used to be), but will be to small when enabling modules like CCK and Views. Set the memory_limit to 16MB under /etc/php5/cgi/php.ini (for ubuntu). Also, the php.ini located under cgi is the php settings for fastcgi and are different from the regular php.ini file you may locate on you server. CGI and FastCGI uses the same php-binary.