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 http://www.lighttpd.net/download/lighttpd-1.4.18.tar.bz2.

$ wget http://www.lighttpd.net/download/lighttpd-1.4.18.tar.bz2

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!

Quick tip - recover a failed download using Wget

GNU wget is a brilliant tool for downloading. Whether it's from the web, FTP or elsewhere, wget is a very powerful and useful tool.

Unfortunately, internet connections are often far from completely stable and if you're downloading something and that download subsequently fails, it can be quite frustrating (especially if it's a big file).

In the vast majority of cases though, there's no need to go about deleting the file and restarting the download from scratch. Wget includes a -c switch that you can use to continue a failed download from where you left off.

Say we're downloading a big file:

$ wget bigfile

And bang - our connection goes dead (you can simulate this by quitting with Ctrl-C if you like). Once we're back up and running and making sure you're in the same directory you were during the original download:

$ wget -c bigfile

Provided where you're downloading from supports it, you should get going from exactly where you left off.

It's a nice quick tip, but it can be a real time (and sanity) saver when you've got a dodgy connection!

View process hierarcy from the command line - pstree

The commands ps and top are very useful for seeing what's running on your system. Operating systems like Linux though actually have a hierarchical system of processes, and by default neither of those two show you that hierarchy.

That's where pstree comes in. As the name suggests, it shows you a tree-style list of processes in this hierarchy. As you can see, depending on the exact flavour of Unix you're running, there might be a different name, but there will be a 'father' process that is right at the top.

pstree

In the case of Linux, that's init. You'll notice that in your output, all processes are underneath this one. You might also discover some interesting relationships between different processes.

It also might turn out useful if something goes awry on your system and if you need to identify the root culprit of a problem (for example if the parent process spawns a child which locks up).

Whether it's out of sheer curiosity, to troubleshoot, or for something else, pstree is a useful tool to have in your command line toolkit.

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. ...
  7. Go to

Sign In

    Enjoy FOSSwire's content? Have it delivered! Subscribe