Lighttpd

By Andre Bogus
books-svg-icon Book
eBook $25.99 $17.99
Print $43.99
Subscription $15.99 $10 p/m for three months
$10 p/m for first 3 months. $15.99 p/m after that. Cancel Anytime!
What do you get with a Packt Subscription?
This book & 7000+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook + Subscription?
Download this book in EPUB and PDF formats, plus a monthly download credit
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook?
Download this book in EPUB and PDF formats
Access this title in our online reader
DRM FREE - Read whenever, wherever and however you want
Online reader with customised display settings for better reading experience
What do you get with video?
Download this video in MP4 format
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with video?
Stream this video
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with Audiobook?
Download a zip folder consisting of audio files (in MP3 Format) along with supplementary PDF
What do you get with Exam Trainer?
Flashcards, Mock exams, Exam Tips, Practice Questions
Access these resources with our interactive certification platform
Mobile compatible-Practice whenever, wherever, however you want
BUY NOW $10 p/m for first 3 months. $15.99 p/m after that. Cancel Anytime!
eBook $25.99 $17.99
Print $43.99
Subscription $15.99 $10 p/m for three months
What do you get with a Packt Subscription?
This book & 7000+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook + Subscription?
Download this book in EPUB and PDF formats, plus a monthly download credit
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook?
Download this book in EPUB and PDF formats
Access this title in our online reader
DRM FREE - Read whenever, wherever and however you want
Online reader with customised display settings for better reading experience
What do you get with video?
Download this video in MP4 format
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with video?
Stream this video
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with Audiobook?
Download a zip folder consisting of audio files (in MP3 Format) along with supplementary PDF
What do you get with Exam Trainer?
Flashcards, Mock exams, Exam Tips, Practice Questions
Access these resources with our interactive certification platform
Mobile compatible-Practice whenever, wherever, however you want
  1. Free Chapter
    Introduction to Lighttpd
About this book
Publication date:
October 2008
Publisher
Packt
Pages
240
ISBN
9781847192103

 

Chapter 1. Introduction to Lighttpd

In this chapter, we will learn:

  • What Lighttpd is

  • How to install Lighttpd

  • How to build Lighttpd using:

    • Autotools

    • CMake

What is Lighttpd? Lighttpd, or Lighty, as it is affectionately called, is an extensible, modular, low-footprint, single-threaded, high performance, web server that will happily run on small servers, and outperform an Apache server or Microsoft IIS in most settings. Lighttpd powers many large sites, such as the YouTube video download servers and the image upload server of Wikipedia. At the time of this writing, Lighttpd has the fifth place in the netcraft web server top ten. The plugin architecture encourages developing custom modules and trying new ideas. The development community around Lighttpd is friendly, helpful and pragmatic, and the documentation, though a little scattered, is quite thorough, if you know where to look.

Installing Lighttpd

Lighttpd has very little dependencies considering the wealth of functionalities it provides. For most systems, getting Lighttpd is just a matter of downloading and installing a package. Before we go out and get one, we better know what we want. There are two branches of Lighttpd: a stable branch and a development branch.

The stable branch is very solid and changes at the most once every two months (if bug fixes are not counted, then about once a year), allowing the developers to concentrate on bug fixes. The development branch moves faster, with a new release every four to six weeks. The development snapshots contain new shiny features, but can also contain hidden bugs, break old features and can generally be less stable.

At the time of writing, version 1.4.19 is deemed to be the stable version, while pre-releases of the upcoming 1.5.0 version are distributed for more testing before the final release. Some systems might have packages of older versions, but anything older than the stable branch many contain known security holes.

For a live server, or if we want the latest versions, we usually compile Lighttpd from sources. For a development server, we might take the easy route and install a precompiled package to leave the worries about dependencies to whoever maintains the package database.

The last question is, on which system we should use Lighttpd? My pragmatic advice is to use what you have. For a development system, take the platform you currently work on. For integration and production platforms, this advice needs to be constrained a little—apart from Windows, which allows too little connections to be open in parallel, most operating systems are suitable for production use—the POSIX-implementing ones (Linux, every BSD, Solaris, Mac OS X, and so on) also benefit from numerous optimizations.

Now, without further ado, here is a list of binary packages per system:

System

Download address or command

Debian GNU/Linux, Ubuntu, Knoppix, other Derivatives

apt-get install libpcre3

apt-get install zlib1g

apt-get install mysql-common libmysqlclient12

apt-get install lighttpd lighttpd-doc

Fedora / Red Hat Novell / SuSE Linux other RPM-based distributions

yum install pcre

yum install zlib

wget http://www.kevindustries.com/media/kw/files/linux/lighttpd/RPMS/lighttpd-1.4.13-3.KWEL4.i386.rpm

Gentoo Linux

emerge lighttpd

Windows

http://www.kevinworthington.com:8181/?cat=20

To compile Lighttpd from source, download the latest source package from http://lighttpd.net/download/. Between Lighttpd versions 1.4.19 and 1.5.0, the build system has changed from Autotools to CMake. Before we can install it, we need the following:

  • A compiler and toolchain—most systems have gcc make and a libc (usually glibc) providing the usual functions. For some embedded platforms, the need to define some constants by hand before cross-compiling has been observed.

  • PCRE—the libpcre package (http://www.pcre.org) supplies PERL-compatible regular expressions to Lighttpd. Lighttpd will run without it, but won't do anything more complex than serving web pages directly under only one hostname and path, without any rewriting or redirecting.

Apart from these, there are some optional packages that expand the capabilities of Lighttpd:

  • OpenSSL (http://openssl.org) or any other SSL library (but OpenSSL is the most-tested one) is needed for transport layer encryption, so our site can be accessed via https.

  • zlib (http://www.zlib.org) is required for mod_compress to supply on-the-fly gzip compression for static content. As virtually every system has zlib available, this should not concern us.

  • bzip2 (http://www.bzip.org) can also be used by mod_compress static content for clients who allow bzip2 compression. It is a little slower than zlib, but achieves higher compression rates.

  • Lua (http://www.lua.org) is a small, fast, powerful scripting language, which is a perfect match for Lighttpd and can be embedded as mod_magnet.

  • MySQL (http://www.mysql.org) is a product by the company that employs the author of Lighttpd. Therefore, it is no surprise that Lighttpd uses MySQL for database-backed virtual hosting. Also, under Debian, a binary install depends on MySQL.

  • pkg-config (http://pkgconfig.freedesktop.org) is not strictly necessary, but it will make the installation easier. Especially for Lua, the Lighttpd installation process relies on it unless given explicit library paths.

 

Installing Lighttpd


Lighttpd has very little dependencies considering the wealth of functionalities it provides. For most systems, getting Lighttpd is just a matter of downloading and installing a package. Before we go out and get one, we better know what we want. There are two branches of Lighttpd: a stable branch and a development branch.

The stable branch is very solid and changes at the most once every two months (if bug fixes are not counted, then about once a year), allowing the developers to concentrate on bug fixes. The development branch moves faster, with a new release every four to six weeks. The development snapshots contain new shiny features, but can also contain hidden bugs, break old features and can generally be less stable.

At the time of writing, version 1.4.19 is deemed to be the stable version, while pre-releases of the upcoming 1.5.0 version are distributed for more testing before the final release. Some systems might have packages of older versions, but anything older than the stable branch many contain known security holes.

For a live server, or if we want the latest versions, we usually compile Lighttpd from sources. For a development server, we might take the easy route and install a precompiled package to leave the worries about dependencies to whoever maintains the package database.

The last question is, on which system we should use Lighttpd? My pragmatic advice is to use what you have. For a development system, take the platform you currently work on. For integration and production platforms, this advice needs to be constrained a little—apart from Windows, which allows too little connections to be open in parallel, most operating systems are suitable for production use—the POSIX-implementing ones (Linux, every BSD, Solaris, Mac OS X, and so on) also benefit from numerous optimizations.

Now, without further ado, here is a list of binary packages per system:

System

Download address or command

Debian GNU/Linux, Ubuntu, Knoppix, other Derivatives

apt-get install libpcre3

apt-get install zlib1g

apt-get install mysql-common libmysqlclient12

apt-get install lighttpd lighttpd-doc

Fedora / Red Hat Novell / SuSE Linux other RPM-based distributions

yum install pcre

yum install zlib

wget http://www.kevindustries.com/media/kw/files/linux/lighttpd/RPMS/lighttpd-1.4.13-3.KWEL4.i386.rpm

Gentoo Linux

emerge lighttpd

Windows

http://www.kevinworthington.com:8181/?cat=20

To compile Lighttpd from source, download the latest source package from http://lighttpd.net/download/. Between Lighttpd versions 1.4.19 and 1.5.0, the build system has changed from Autotools to CMake. Before we can install it, we need the following:

  • A compiler and toolchain—most systems have gcc make and a libc (usually glibc) providing the usual functions. For some embedded platforms, the need to define some constants by hand before cross-compiling has been observed.

  • PCRE—the libpcre package (http://www.pcre.org) supplies PERL-compatible regular expressions to Lighttpd. Lighttpd will run without it, but won't do anything more complex than serving web pages directly under only one hostname and path, without any rewriting or redirecting.

Apart from these, there are some optional packages that expand the capabilities of Lighttpd:

  • OpenSSL (http://openssl.org) or any other SSL library (but OpenSSL is the most-tested one) is needed for transport layer encryption, so our site can be accessed via https.

  • zlib (http://www.zlib.org) is required for mod_compress to supply on-the-fly gzip compression for static content. As virtually every system has zlib available, this should not concern us.

  • bzip2 (http://www.bzip.org) can also be used by mod_compress static content for clients who allow bzip2 compression. It is a little slower than zlib, but achieves higher compression rates.

  • Lua (http://www.lua.org) is a small, fast, powerful scripting language, which is a perfect match for Lighttpd and can be embedded as mod_magnet.

  • MySQL (http://www.mysql.org) is a product by the company that employs the author of Lighttpd. Therefore, it is no surprise that Lighttpd uses MySQL for database-backed virtual hosting. Also, under Debian, a binary install depends on MySQL.

  • pkg-config (http://pkgconfig.freedesktop.org) is not strictly necessary, but it will make the installation easier. Especially for Lua, the Lighttpd installation process relies on it unless given explicit library paths.

 

Building Lighttpd using Autotools


Lighttpd was built using Autotools until version 1.5.0, in which the authors experimented with CMake (and other build systems). The Autotools build system has been around for some time. So, almost every system that has a sufficient toolchain can build Lighttpd.

Note that the building can and should be done as a normal user, while the installation must usually be done as a superuser, unless the target directory is owned by the normal user. The easiest way (provided we have sudo) is:

configure && make && sudo make install

Before we enter this command line, we can set a few environment variables that will affect the build process. We can do this in a bash compatible shell using:

export SOME_VAR=X

This will set the variable SOME_VAR to X and export it to the shell. Alternatively, we can just omit the export if we write the variable declarations at the beginning of our command, as in:

SOME_VAR=X; OTHER_VAR=Y; configure

Here are the most important variables:

Variable name

Useful value

Description

CC

arm-gcc icc

Specify an alternate compiler if you cross-compile Lighttpd or have a more optimizing compiler compared to gcc.

CFLAGS LDFLAGS

-g -Os -L/usr/local/lib

These options go to the gcc compiler. Read up on gcc for further information.

PKG_CONFIG

/opt/pkg_config

We may need to specify where pkg-config is, if configure cannot find it.

FAM_CFLAGS FAM_LIBS

-I/opt/fam/include -L/opt/fam/lib

We can specify alternate C Flags and linker settings (for example, paths) for FAM.

LUA_CFLAGS LUA_LIBS

-I/usr/include/lua/ -llua

This tells configure where to find Lua (for example, if pkg-config is missing)

configure takes some options to select features. These options are usually expressed as:

configure --with-lua=/usr/src/lua-5.1 --with-pcre

Note that for every "with-something" option, there also is a "without-something" option that does the exact opposite. Here are the most important options:

Parameter (example)

Description

--help

This makes configure print a help screen and exit.

--prefix=/usr/ --prefix=/opt/lighttpd/

Specify your installation directory if you want to install Lighttpd at a location different from default/usr/local/.

--bindir=... --sbindir=... --datadir=... --libdir=... --sysconfdir=...

We can also set each directory individually for the installation process.

--host=PLATFORM --target=PLATFORM --build=PLATFORM

If we want to cross-compile Lighttpd or have different platforms to compile Lighttpd against, we can specify them here. Usually, we can leave these settings alone.

--enable-static --enable-shared

Makes configure build static or shared libraries to link to the Lighttpd executable. The same default is shared.

--enable-lfs

This option enables large files (above 2Gig). Set it if you host HD-movies or large genome sequence files.

--disable-ipv6

Lighttpd by default can use IPv6 in addition to the usual IPv4. Disabling it may reduce the size a little bit and quell our fears of possible bugs in the IPv6 implementation, but may leave out all users of next-gen Internet technologies in the cold.

--with-pcre

This is on by default if PCRE is available. You probably want it anyway, unless your target system is embedded.

--with-openssl

This enables SSL (usually using OpenSSL).

--with-kerberos5

This makes configure use the kerberos5 support supplied by OpenSSL.

--with-zlib --with-zlib=/usr/local/lib/

This adds libgz compression to Lighttpd (via mod_compress). If the path is omitted, configure will try to infer it.

--with-bzip --with-bzip=/opt/lib/

This adds bzip2 compression to Lighttpd (via mod_compress). See --with-zlib.

--with-fam --with-fam=/opt/fam/

This activates the use of the FAM/gamin stat cache which speeds up Lighttpd considerably on repeated requests for the same file.

--with-ldap

This allows Lighttpd to authenticate users (in mod_auth) against an LDAP directory.

--with-webdav-props --with-webdav-locks

These options enable properties and locks in WebDAV (mod_webdav).

--with-gdbm --with-memcache

These options enables the use of GDBM or memcached storage in mod_trigger_b4_dl, respectively.

--with-atttr

This makes Lighttpd support XFS' extended attributes to get the MIME type for a file (by mimetype.use-xattr).

--with-mysql --with-mysql=/opt/mysql/

This option adds MySQL support by mod_mysql_vhost. The optional path should contain mysql_config.

--with-lua --with-lua=/usr/src/lua

This enables the use of the Lua programming language to be embedded into lightTPD as mod_magnet.

--with-valgrind

This adds internal valgrind support. We only need this if we want to debug Lighttpd memory usage.

The make utility will use the Makefile that configure has generated to build and install Lighttpd. Configure Lighttpd to your needs, but the defaults will take care of most of them.

 

Building Lighttpd using CMake


Starting with 1.5.0, the Lighttpd developers tried using CMake instead of Autotools to speed up the build process. However, it was apparently removed in the development snapshots, for which Autotools are used. If we come across a version with a CMakeLists.txt file, we can build it using CMake.

CMake can be run with the -i option to start it in the wizard mode so that we are queried on all options. This is probably the easiest way of setting up Lighttpd, but depending on how many installations we have we might want to do a command-line install. In this case, cmake -L gives us a list of options, which we can supply via the -D switch, as in:

cmake -DWITH_OPENSSL:BOOL=OFF -DCMAKE_INSTALL_PREFIX:PATH=/home/lighty

Note

Options of the type BOOL can take the values ON, OFF (or TRUE, False, Y, N, and so on). All other types are basically handled like strings. The naming of the options should be similar to the options for Automake in the preceding table.

 

Summary


Regardless of whether we use precompiled packages for our target operating system, or compile our own Lighttpd, the setup would not be much easier. A seasoned administrator will compile and install a basic Lighttpd in under 15 minutes (in fact even a less weathered one can do, since this is what I timed on my last attempt to install 1.4.19).

Now that we have installed our Lighttpd, let us get it up and running.

About the Author
  • Andre Bogus

    Andre Bogus is a musician turned programmer. He has worked in different jobs from voice acting to programming to teaching to managing software projects. At the moment he works as a consultant and implementer for KOGIT GmbH, an Identity Management company based in Germany. He found Lighttpd while searching for the ideal software for his personal web server and quickly learned the tricks to make it do what he wanted. He enjoys learning new things and telling others about them. When his full schedule allows it, he can be found on the #lighttpd IRC channel.

    Browse publications by this author
Lighttpd
Unlock this book and the full library FREE for 7 days
Start now