This short tutorial is going to show how to set up Lighttpd with fastcgi on Debian 4.0 (Etch). Actually it’s nothing special but I hope it demonstrates how easy it is. ;-)
What is Lighttpd?
Lighttpd is a light (I bet you already guessed that … ;)), fast and secure high performance web server. It perfectly fits the needs for high load websites but it’s not the best choice for servers hosting multiple independant websites. There are some popular sites running on lighttpd (eg. Youtube).
If you’ve been running apache, the first step is to stop it:
Afterwards you can savely install the lighttpd package:
aptitude install lighttpd
It should install smoothly and start itself when finished.
Lighttpds default configuration on Debian file is
/etc/lighttpd/lighttpd.conf. The default settings might be
just fine for your needs, but it’s a bit messy for my taste. So let’s
simply write our own. Open the configuration with your favorite editor.
The first thing we need to do is loading the required modules. This is what we’ll use for this tutorial:
# Modules server.modules = ( "mod_access", "mod_alias", "mod_accesslog", "mod_rewrite", "mod_compress", "mod_evhost" )
Of course there are a lot more modules. Just take a look at the list
provided in the Lighttpd documentation wiki.
mod_evhost to simulate multiple virtual hosts. More on this later.
Next we’ve to set some required values in order to get the server working. This should be self explaining:
# Server settings server.port = 80 server.pid-file = "/var/run/lighttpd.pid" server.username = "www-data" server.groupname = "www-data" # Document root server.document-root = "/var/www/default"
In order to use logging we also need to set the following two paths:
# Logs server.errorlog = "/var/log/lighttpd/error.log" accesslog.filename = "/var/log/lighttpd/access.log"
You also might want to set index file names and enable directory listing. Do this by adding this to your configuration file:
# Index files index-file.names = ( "index.php", "index.html", "index.htm" ) # Directory listing server.dir-listing = "enable"
To finish the basic configuration we’ve to add two more lines. They’re used to load more configuration files located in
/etc/lighttpd/conf-enabled/ and to load the mime-types:
# External configuration files include-shell "/usr/share/lighttpd/create-mime.assign.pl" include-shell "/usr/share/lighttpd/include-conf-enabled.pl"
Don’t forget to save! ;-)
Enabling fastcgi support
In order to use ruby or php on our server we need to activate lighty’s fastcgi module. This can be done by running:
You’ll see a list of available modules and asked to enter the module in
fastcgi). Afterwards open up
/etc/lighttpd/conf-enabled/10-fastcgi.conf to see the
fastcgi configuration. By default php4 support is enabled. In order to use it you need to install
aptitude install php4-cgi
In order to use the newly created configuration file we need to restart lighttpd:
That’s it! Now go and place a file like this called
<?php phpinfo(); ?>
View it’s output by visiting http://www.your-domain.com/info.php. If everything worked you should now see php’s details.