Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Lighttpd
Lighttpd

Lighttpd: Installing, compiling, configuring, optimizing, and securing this lightning-fast web server

By Andre Bogus
$25.99 $17.99
Book Oct 2008 240 pages 1st Edition
eBook
$25.99 $17.99
Print
$43.99
Subscription
$15.99 Monthly
eBook
$25.99 $17.99
Print
$43.99
Subscription
$15.99 Monthly

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Buy Now

Product Details


Publication date : Oct 29, 2008
Length 240 pages
Edition : 1st Edition
Language : English
ISBN-13 : 9781847192103
Concepts :
Table of content icon View table of contents Preview book icon Preview Book

Lighttpd

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.

Left arrow icon Right arrow icon

Key benefits

What you will learn

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Buy Now

Product Details


Publication date : Oct 29, 2008
Length 240 pages
Edition : 1st Edition
Language : English
ISBN-13 : 9781847192103
Concepts :

Table of Contents

20 Chapters
Lighttpd Chevron down icon Chevron up icon
Credits Chevron down icon Chevron up icon
About the Author Chevron down icon Chevron up icon
About the Reviewer Chevron down icon Chevron up icon
1. Preface Chevron down icon Chevron up icon
1. Introduction to Lighttpd Chevron down icon Chevron up icon
2. Configuring and Running Lighttpd Chevron down icon Chevron up icon
3. More Virtual Hosting and CGI Chevron down icon Chevron up icon
4. Downloads and Streams Chevron down icon Chevron up icon
5. Big Brother Lighttpd Chevron down icon Chevron up icon
6. Encryption: SSL Chevron down icon Chevron up icon
7. Securing Lighttpd Chevron down icon Chevron up icon
8. Containing Lighttpd Chevron down icon Chevron up icon
9. Optimizing Lighttpd Chevron down icon Chevron up icon
10. Migration from Apache Chevron down icon Chevron up icon
11. CGI Revisited Chevron down icon Chevron up icon
12. Using Lua with Lighttpd Chevron down icon Chevron up icon
13. Writing Lighttpd Modules Chevron down icon Chevron up icon
HTTP Status Codes Chevron down icon Chevron up icon
Module/Configuration Index Chevron down icon Chevron up icon

Customer reviews

Filter icon Filter
Top Reviews
Rating distribution
Empty star icon Empty star icon Empty star icon Empty star icon Empty star icon 0
(0 Ratings)
5 star 0%
4 star 0%
3 star 0%
2 star 0%
1 star 0%

Filter reviews by


No reviews found
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.