Installing Lighttpd from source on Linux

lighttpd logo Apache is the world's most popular web server and is a very good piece of software. It isn't however, the only choice of free software and open source web server solutions and it's easy to overlook lightweight alternatives to Apache.

One such alternative is lighttpd. Here's what its official site says about the project:

Security, speed, compliance, and flexibility -- all of these describe lighttpd (pron. lighty) which is rapidly redefining efficiency of a webserver; as it is designed and optimized for high performance environments. With a small memory footprint compared to other web-servers, effective management of the cpu-load, and advanced feature set (FastCGI, SCGI, Auth, Output-Compression, URL-Rewriting and many more) lighttpd is the perfect solution for every server that is suffering load problems. And best of all it's Open Source licensed under the revised BSD license.

In this tutorial, I am going to show you how to get lighttpd up and running by compiling it from source. You can of course use your distribution's package manager to install it, but here we'll go through the source-based process.

First of all, we need to head over to the Lighttpd website and download the latest source code. At the time of writing, that is 1.4.18, and the download link is

$ wget

Once that's downloaded, we'll extract the archive (substitute xjvf for xzvf and the relevant filename in the next command if you downloaded the tar.gz version):
$ tar xjvf lighttpd-1.4.18.tar.bz2

Now, we need to change into the newly extracted directory (change your version numbers if necessary):
$ cd lighttpd-1.4.18

The install is a standard source-based process. If you're familiar with that, then go ahead. For everyone else, the sequence is to run the following commands in order (obviously letting the first one finish before starting the second one and so on).
$ ./configure
$ make

Finally, you need to run make install as root. On Ubuntu, run sudo make install. Everywhere else, do this:
$ su -c "make install"

Enter your root password (or your user password in the case of Ubuntu) and confirm. That's the basic installation now done, so let's get our server up and running!

Before we do that, however, we have to get a configuration file in place and set up. Depending on your exact requirements, you'll need to have a configuration file for you. In this example, I'm going to use a very basic configuration file to get us up and running as soon as possible. You can find more help on making configuration files here on the lighttpd wiki.

server.document-root = "/var/www/"

server.port = 80

server.username = "www-data"
server.groupname = "www-data"

mimetype.assign = (
".html" => "text/html",
".txt" => "text/plain",
".jpg" => "image/jpeg",
".png" => "image/png"

static-file.exclude-extensions = ( ".fcgi", ".php", ".rb", "~", ".inc" )
index-file.names = ( "index.html" )

Save your configuration file as /etc/lighttpd/lighttpd.conf.

Back on your command line, login as root. For Ubuntu, use sudo -i or su - for everyone else. We now need to start the server daemon for the first time.

# lighttpd -D -f /etc/lighthttpd/lighttpd.conf

You should get a message along these lines:
2007-09-14 20:30:25: (log.c.75) server started

That means your server started up successfully and you should now be able to browse to http://localhost on your machine and view whatever is in /var/www (or whatever you chose as your root for the web server). Now you can get populating this directory with content!

Avatar for peter Peter Upfold -

Peter Upfold is a technology enthusiast from the UK. Peter’s interest in Linux stems back to 2003, when curiosity got the better of him and he began using SUSE 9.0. Now he runs Linux Mint 9 on the desktop, runs a CentOS-based web server from home for his personal website and dabbles in all sorts of technology things across the Windows, Mac and open source worlds.

Home » Articles »

Discussion: Installing Lighttpd from source on Linux

  1. Josh (guest)

    # Posted on 15 September 2007 at 09:32 PM

    As always, awesome tutorial... just one thing;

    lighttpd-1.4.18.tar.bz2 should be lighttpd-1.4.18

  2. Peter (guest)

    # Posted on 16 September 2007 at 03:14 AM

    Thanks for that correction Josh!

  3. Yuanjin (guest)

    # Posted on 17 September 2007 at 07:31 AM

    Well, that is good. Does it support most website services?

  4. Peter (guest)

    # Posted on 17 September 2007 at 10:02 AM

    lighttpd supports FastCGI, so you can run all sorts of dynamic applications and languages on top of it. See their website for more information. ;)

  5. Tengku Asmadi (guest)

    # Posted on 04 October 2007 at 09:45 AM

    Guys, sorry if my question here is very basic because I new to this.

    I tried the above tutorial and received this error. What should I do?

    Here it is:

    drasmadi@drasmadi-kubuntu:~/lighttpd-1.4.18$ ./configure checking build system type... i686-pc-linux-gnulibc1 checking host system type... i686-pc-linux-gnulibc1 checking target system type... i686-pc-linux-gnulibc1 checking for a BSD-compatible install... /usr/bin/install -c checking whether build environment is sane... yes checking for a thread-safe mkdir -p... /bin/mkdir -p checking for gawk... no checking for mawk... mawk checking whether make sets $(MAKE)... yes checking whether to enable maintainer-specific portions of Makefiles... no checking for gcc... gcc checking for C compiler default output file name... configure: error: C compiler cannot create executables See `config.log' for more details. drasmadi@drasmadi-kubuntu:~/lighttpd-1.4.18$

  6. Peter (guest)

    # Posted on 04 October 2007 at 11:31 AM

    @Tengku - check to make sure you have your distribution's development tools packages installed correctly.

    While you have the gcc compiler installed, it looks as the configuration isn't quite right.

    Installing or re-installing the development tools from Adept should help.

  7. Tengku Asmadi (guest)

    # Posted on 04 October 2007 at 04:33 PM

    The previous problem solved after I ran the following command:

    $sudo apt-get install libc6-dev g++ gcc

    Now another problem appeared when i tried to start the server for the first time as below:

    root@drasmadi-kubuntu:~# lighttpd -D -f /etc/lighttpd/lighttpd.conf 2007-10-05 07:26:07: (configfile.c.796) source: /etc/lighttpd/lighttpd.conf line: 1 pos: 24 invalid character in variable name 2007-10-05 07:26:07: (configfile.c.852) configfile parser failed at: =

    the lighttpd.conf has already been created using a text editor and saved under /etc/lighttpd/ with the following lines as you suggested:

    server.document-root = “/var/www/”

    server.port = 80

    server.username = “www-data” server.groupname = “www-data”

    mimetype.assign = ( “.html” => “text/html”, “.txt” => “text/plain”, “.jpg” => “image/jpeg”, “.png” => “image/png” )

    static-file.exclude-extensions = ( “.fcgi”, “.php”, “.rb”, “~”, “.inc” ) index-file.names = ( “index.html” )

    So, what have I done wrong?

  8. Tengku Asmadi (guest)

    # Posted on 04 October 2007 at 04:54 PM

    Oh, forget the above error messages, it didn't recognise the " character when I copied the text directly from your blog. I edited the " and now it run but unfortunately it hanged as follows:

    root@drasmadi-kubuntu:~# lighttpd -D -f /etc/lighttpd/lighttpd.conf 2007-10-05 07:45:57: (log.c.75) server started

    It doesn't return the prompt back to me. Is this normal?

    When I typed http://localhost/ in my browser it returned

    404 - Not Found

    The are already some php files there under /var/www/

    Any idea?

  9. Rameshkumar (guest)

    # Posted on 07 October 2007 at 11:19 AM

    Hi ,

    I have already configured normal httpd (apache), i need to transfer the load to lighthttpd, is there is anyway?

  10. # Posted on 09 October 2007 at 03:11 AM

    [...] you’ve got your very own Lighttpd server up and running as per this tutorial, but you want to serve a little more than just static [...]

  11. lefty.crupps (guest)

    # Posted on 15 October 2007 at 09:20 PM

    Rameshkumar, i would think that you could stop the Apache server (/etc/init.d/apache2 stop) and start the lighttpd server (/etc/init.d/lighttpd start) and it would pick up serving websites.

    you would, of course, have to have both (well, lighttpd) configured properly; you may want to test this on another computer first.

    thanks for the tutorial, I'll hav to check it out.

  12. Krupa (guest)

    # Posted on 29 July 2008 at 04:24 AM

    when I typed (while in root) lighttpd -D -f /etc/lighttpd/lighttpd.conf sometimes I get access.log Permission denied message and at other times prompt does not return. I'm totally new to this and need explanation in detail. thankyou

  13. Tapas Mishra (guest)

    # Posted on 04 August 2010 at 07:05 AM

    I followed what you did but there was no error and also the server did not started. I did

    cd /usr/src/lighttpd-1.4.x/ ./configure make make install

    There was no init script for lighttpd. So what do I do also /usr/src/lighttpd-1.4.x/doc/lighttpd.conf does not exist instead /usr/src/lighttpd-1.4.x/doc/config/lighttpd.conf

    is there. Apart from this the init script for lighttpd seemed to be in /usr/src/lighttpd-1.4.x/doc/initscripts/rc.lighttpd and copying this to /etc/init.d/rc.lighttpd did not helped me. So what do I need to do ?

Home » Articles » Installing Lighttpd from source on Linux