Revision of Lighttpd from Fri, 10/21/2011 - 14:32

Revisions allow you to track differences between multiple versions of your content, and revert back to older versions.

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.

Prerequisites
lighttpd requires the headers for libprce and zlib. If the lighttpd configure script can't find them, you'll need to install them.
pcre:

cd /extra/src
wget http://sourceforge.net/projects/pcre/files/pcre/8.00/pcre-8.00.tar.gz/download
tar zxvf pcre-8.00.tar.gz
cd pcre-8.00
./configure
make
make install

or, with CentOS 5, install the pcre-devel package:

yum install pcre-devel

zlib:

cd /extra/src
wget http://www.zlib.net/zlib-1.2.3.tar.gz
tar zxvf zlib-1.2.3.tar.gz
cd zlib-1.2.3
./configure
make
make install

The install might also complain about not finding the bzip2 headers. If that's the case:

yum install bzip2-devel

Installation
Download the latest version of the lighttpd source (1.4.29 at time of writing):

mkdir -p /extra/src
cd /extra/src
wget http://download.lighttpd.net/lighttpd/releases-1.4.x/lighttpd-1.4.29.tar.gz
tar zxvf lighttpd-1.4.29.tar.gz
cd lighttpd-1.4.29

Configure, build and install:

./configure
make
make install

Daemontools Startup
Lighttpd is well-suited for being supervised by daemontools. The application configuration files can be placed below the service directory, similar to how djbdns does it.
Assuming you have already installed daemontools, create the directories to hold the lighttpd run script, logging script, and config files:

mkdir -p /var/service
cd /var/service
mkdir -m 1755 lighttpd
cd lighttpd

Create the run script (/var/service/lighttpd/run), with the following:

#! /bin/sh

exec 2>&1
exec lighttpd -D -f ./root/lighttpd.conf

Once you have saved the file, change it's permissions to it can be executed:

chmod 700 run

Then create a directory to hold your lighttpd config files:

mkdir -m 755 root

Create the logging service:

mkdir -m 755 log
cd log
wget http://qmail.jms1.net/scripts/run.log
mv run.log run
chmod 700 run

Lighttpd Configuration
The Lighttpd configuration tutorial outlines some options for your lighttpd configuration file, /var/service/lighttpd/root/lighttpd.conf, to get a basic server running. A basic config file could be:

server.document-root = "/var/websites/www.example.org/htdocs/"

server.port = 80

server.username = "nobody"
server.groupname = "nobody"

mimetype.assign = (
  ".html" => "text/html",
  ".txt" => "text/plain",
  ".jpg" => "image/jpeg",
  ".png" => "image/png",
  ".gif" => "image/gif",
  ".pdf" => "application/pdf",
  ".css" => "text/css",
  ".js" => "text/javascript",
)

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

The LighttpdUnderSuperviseExampleConfiguration wiki page has more detailed instructions on how you can organize your configuration.

Start Lighttpd
Once you have created your basic configuration, create a test website:

mkdir -p /var/websites/www.example.org/htdocs/
echo 'OMG, This tutorial worked' > /var/websites/www.example.org/htdocs/test.txt

Create the symbolic link to start the lighttpd service

ln -s /var/service/lighttpd /service/lighttpd

Recent Updates

  • 1 year 11 months ago
  • 1 year 11 months ago
  • 1 year 12 months ago
    php 8.x
  • 1 year 12 months ago
    10.6.7
  • 2 years 2 hours ago
    Drop Centos 5/6 stuff