A [closer] look at lighttpd.conf & its constituents

January 21st, 2013

In the last guide, I showed you how to install the lighttpd web server,

in this post, I will discuss the lighttpd.conf located at /etc/lighttpd/lighttpd.conf & the various configurations available.



  • Continued configuration
  • Configuration overview
  • Name based virtual hosting
  • Error handlers

Continued configuration 

This explains what to do after the previous post.


If you have recently installed the lighttpd web server, point your browser to your domain.

If all is well, you should see this placeholder page (named index.lighttpd.html).

To edit the directory, and/or index page,

navigate to your server document root (as defined by lighttpd.conf - explained here)



Configuration overview

This is a brief overview of the directives in your config file.



This is a shorten list of the configuration options, a full list is available here.



server.document-root: The top level document root

server.port: The server port, default 80.

server.upload-dirs: The upload directory

server.max-connections: How many concurrent connections supported by the server. 1/2 recommended.

server.max-fds: Max file descriptors - set higher than max-connections (max-connections == max-fds/2)

server.max-keep-alive-idle: Maximum seconds before a idling keep-alive connection is dropped

connection.kbytes-per-second: Maximum kilobytes that a connection is limited to

server.kbytes-per-second: Limits the maximum kilobytes for the entire server. (kbyte/s)

server.max-request-size: Maximum size (kbyte) of request



mod_access: Access restrictions

mod_alias: Directory aliases

mod_compress: Reduces network load

mod_redirect: Redirects set of URLS


Let's take a look at the server document root, given by the core directive:

server.document-root =

This specifies where the top level document root is located, you can change it to specify where the default directory is.

(For example:  server.document-root = "/home/lighttpd/public_html/")

In order to have a fully running web server, you must specify the correct directory.


Name based virtual hosting

This enabled you to host multiple websites from a single IP address.


This example shall create 'website1' and 'website2'.


  • Firstly, you must have the required directories for the websites you want to host.


To do this:


# mkdir -p /home/lighttpd/default/http/

This is going to be our default 'main' document root.


# mkdir -p /home/lighttpd/website1.com/http
# mkdir -p /home/lighttpd/website1.com/logs
# mkdir -p /home/lighttpd/website2.com/http
# mkdir -p /home/lighttpd/website2.com/logs

These are our default document root & logs for website1 & website2.


  • Next, we will edit the lighttpd.conf file:
# vi /etc/lighttpd/lighttpd.conf


Change the default document root & point it to our defined document root:

server.document-root = "/home/lighttpd/default/http/"


Add the following lines:

include "website1.com.conf"
include "website2.com.conf"


Save and exit (:wq).


  • Creating website virtual host configuration:


Edit website configuration:


# vi /etc/lighttpd/website1.com.conf


Add the following lines:

$HTTP["host"] =~ "website1\.com" {
              server.document-root = "/home/lighttpd/website1.com/http"
              accesslog.filename = "/home/lighttpd/website1.com/logs/access.log"

(Simply replace the underlined with your website domain/directory)

Save and close (:wq)


Repeat this process for website2;


# vi /etc/lighttpd/website2.com.conf


Add the following lines:


$HTTP["host"] =~ "website2\.com" {
              server.document-root = "/home/lighttpd/website2.com/http"
              accesslog.filename = "/home/lighttpd/website2.com/logs/access.log"


Save and quit.


  • Force reload lighttpd:
/etc/init.d/lighttpd force-reload




Error Handlers

This will detail how to customize your 404 status page using lighttpd web server.


  • Edit your lighttpd.conf:


# vi /etc/lighttpd/lighttpd.conf

  • Add the line:


server.error-handler-404 = "/error-404.php"

This calls upon the file 'error-404.php' located in the website's document root whenever a 404 error has been returned.


  • Save and exit - you're done!



Lighttpd + PHP5 and MySQL on Debian Squeeze (Part 1): Lighttpd

January 21st, 2013

This three part guide will help you install the lighttpd web server along with PHP5 and MySQL support.


Installing and configuring the Lighttpd web server:


Use the Debian aptitude/apt-get command to install lighttpd:

# aptitude install lighttpd


**skip to the configuration section 


Install from source:

*You can choose to use the release/snapshot from the lighttpd or compile from SVN:


1. Extract the tar

                # tar -xf lighttpd-1.4.XXX.tar.gz

2.  Enter the new directory:

           # cd lighttpd-1.4.XXX
  •  Compile from SVN:
  # svn checkout svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x/
  # ./audogen.sh
  # svn update
  # ./autogen.sh

Build dependencies

 #aptitude build-dep lighttpd
 # ./configure
 # make

# su make install

Init script 

sed -e 's/FOO/lighttpd/g' doc/initscripts/rc.lighttpd > /etc/init.d/lighttpd
chmod a+rx /etc/init.d/lighttpd
cp -p doc/initscripts/sysconfig.lighttpd /etc/sysconfig/lighttpd
mkdir -p /etc/lighttpd

# < 1.4.27
install -Dp ./doc/lighttpd.conf /etc/lighttpd/lighttpd.conf

# > 1.4.28
cp -R doc/config/conf.d/ doc/config/*.conf doc/config/vhosts.d/ /etc/lighttpd/

chkconfig lighttpd on


Configuring Lighttpd

*further reading on lighttpd.conf


The lighttpd configuration file is located at /etc/lighttpd/lighttpd.conf


Sample lighttpd.conf


# vi /etc/lighttpd/lighttpd.conf
  • Make the appropriate changes to the lighttpd server directives (i.e. server.upload-dirs/server.document-root)
  • Check that your configuration is working:
#lighttpd -t -f /etc/lighttpd/lighttpd.conf
#lighttpd -D -f /etc/lighttpd/lighttpd.conf

If all goes well you should see the message "Syntax OK"

  • Save and exit out of the file (if you are using vim: !Esc followed by :wq)
  • Start the lighttpd service:
# /etc/init.d/lighttpd start
  • Make sure that the service is running:
# /etc/init.d/lighttpd status OR
# netstat -ntulp


Remove apache2 web server:


Make sure apache2 has stopped:

             # /etc/init.d/apache2/stop

Remove apache2:

# aptitude purge apache2 apache2-utils apache2.2-bin apache2-common
# aptitude autoremove



For troubleshooting, check the lighttpd wiki or the support forum


Part 2: Lighttpd + PHP5 and MySQL on Debian Squeeze (Part 2): PHP5


Further readings: 





January 20th, 2013

i'm bill

this is my blog,



server proudly supports

debian, lighttpd