Official website for Linux User & Developer

Master lighttpd – the lightweight alternative to Apache

Posted by Gavin Thomas

Is your Apache web server too slow? Koen Vervloesem shows you how to use lighttpd instead. This lightweight web server alternative is perfect for virtual private servers and ageing hardware solutions…

This article originally appeared in issue 92 of Linux User & Developer magazine.Master lighttpd - the lightweight alternative to Apache Subscribe and save more than 30% and receive our exclusive money back guarantee – click here to find out more.

Apache is obviously the most popular open source web server, and it’s a good one too. But in some circumstances it really pays off to look at alternatives. For instance, when you rent a virtual private server with not much RAM, you’ll soon meet the limits of Apache. By default, this web server is quite resource-hungry and although there are ways to let it use less memory, tuning Apache is something of a dark art.

So if you don’t have the time to fine-tune Apache on your low-end VPS, why not try another web server? lighttpd (pronounced ‘lighty’) is a promising alternative, because its developers are focusing on performance and simplicity. Moreover, most of the functionality you are used to in Apache – such as modules, URL rewriting and support for CGI and FastCGI – is also available in lighttpd.

The main difference between the two web servers is simple: Apache creates a separate process for each request, whereas lighttpd is able to process multiple requests inside one process. That’s why the latter uses less RAM, as well as less processor time. And that’s why lighttpd can be a better choice than Apache when your server has a small amount of RAM or has to handle large amounts of requests. The latter situation explains why lighttpd is used by popular websites such as Wikipedia and YouTube, and the former situation is why you could benefit from using lighttpd on your VPS to host your blog.

Installing and configuring lighttpd

lighttpd blog
lighttpd documentation
lighttpd forums

lighttpd is available in the repositories of most mainstream Linux distributions. Just install the lighttpd package and maybe some lighttpd-mod packages for extra modules. After starting the web server manually with ‘/etc/init.d/lighttpd start’, it normally starts serving the webpages in /var/www or (in openSUSE) /srv/www/htdocs. For this article, we used Debian Lenny (5.0).

All configuration of lighttpd is done in the file /etc/lighttpd/lighttpd.conf. The syntax is simple: each line has a variable name, an equals sign and the value of the variable. Strings and Boolean values are surrounded by double quotes; numbers are not. A list is surrounded by parentheses and uses commas to separate its elements.

Some basic variables you have to define are the document root and the port that lighttpd is listening to:
[sourcecode language=”bash”]server.document-root = “/var/www/”
server.port = 80
You’ll also want to define the location of the error log and access log (which needs the mod_accesslog module, which is enabled by default):
[sourcecode language=”bash”]server.errorlog = “/var/log/lighttpd/error.log”
accesslog.filename = “/var/log/lighttpd/access.log”
If you don’t want to show a directory listing in directories without an index file, add the following line:
[sourcecode language=”bash”]dir-listing.activate = “disable”
Now after you have changed something in the configuration file, you have to tell lighttpd to reload it:
[sourcecode language=”bash”]/etc/init.d/lighttpd force-reload
It’s also a good idea to test the syntax of the configuration file first:
[sourcecode language=”bash”]lighttpd -t -f /etc/lighttpd/lighttpd.conf
Continue to page 2…

Return to the Linux User & Developer homepage

twitter follow us
Pages: 1 2 3
  • Tell a Friend
  • Follow our Twitter to find out about all the latest Linux news, reviews, previews, interviews, features and a whole more.
    • me

      I like lighttpd but it has one serious issue why I don’t use it in production. It is not standard part of CentOS and RedHat distribution (official RPM package is not available). :-(

    • Thanks for a really interesting article about lighttpd (or “lighty”).

      It’s so easy to just use the default Apache when setting up something.
      Maybe lighttpd is _the_ alternative when it comes to older systems.

      Bookmarked this for future reference.


    • I have never tested lighttpd, but to avoid the big resource consumer Apache.
      I am running Nginx as a reverse proxy with Apache behind.

      Here is how I configured it to run Drupal with Boost:

    • Hello experts. would you be interested in offering remote services on LIGHTTPD to our customer. Please let me know using