Lighttpd - Install and configuration for Drupal

Introduction

Updated: 04.04.2008 (compatible with Ubuntu Hardy Heron)

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 for every request, FastCGI uses a single persistent process which handles many requests over its lifetime.

Installation

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

You will be introduced to two ncurses interfaces during the install, one for mysql root password. And one for phpmyadmin server config. Set your root password and choose lighttpd for phpmyadmin server config.

Let's get on with server configuration..

Configuration
You need to edit 2 files,

  • lighttpd.conf
  • and

  • php.ini

Then download 1 file named drupal.lua:

$ wget http://pixel.global-banlist.de/drupal.lua
$ sudo cp drupal.lua /etc/lighttpd/

Change the binary path for php and increase the php memory limit:

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

$ sudo vim /etc/lighttpd/lighttpd.conf

and add the following configuration:


$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 && sudo lighty-enable-mod magnet
$ sudo /etc/init.d/lighttpd force-reload

Then visit http://localhost/phpmyadmin to verify that your php works.

There you go, fly light! ;)

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

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

Some more info about clean urls and lua
mod_magnet depends on lua5.1+
For history, see
reference: http://pixel.global-banlist.de./2006/10/6/dr-magneto-vs-mr-404-handler

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-6.1"
to
$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. 16MB is default (or at least used to be), but will be too small when enabling modules like CCK and Views. Set the memory_limit to 32MB 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.

Comments

Post new comment

  • Allowed HTML tags: <strong> <code>
  • Lines and paragraphs break automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.

More information about formatting options