Installing Lighttpd

Startingpoint: You want to install lighttpd and PHP on a completely naked distribution.

  • using precompiled packages
  • compiling from source

Installing precompiled Packages

Before you can install you have to fulfill some requirements:

  • libpcre
  • libz

Lighttpd has several modules which require additional libraries.

RPM

(for redhat and friends)
$ yum install pcre
$ yum install zlib

Go to http://www.lighttpd.net/download/ and fetch the fitting RPM for your platform and install it. If you are using Fedora, you can find a RPM in the distribution repos.

$ wget http://www.lighttpd.net/download/lighttpd-1.3.15-1.i586.rpm
$ rpm -Uhv lighttpd-1.3.15-1.i586.rpm

Alternatively, the following command will do all at once:

$ sudo yum install pcre zlib lighttpd

Skip to Configuration.

Debian

First, check of the requirements are ok:

$ apt-get install libpcre3
$ apt-get install zlib1g
$ apt-get install mysql-common libmysqlclient12

Go to http://www.lighttpd.net/download/ and download the debian package for your distribution/platform.

$ wget http://www.lighttpd.net/download/debian/sarge/lighttpd_1.4.3-1_i386.deb
$ dpkg -i lighttpd_1.4.3-1_i386.deb

If there is no debian package for your platform you have to compile it yourself.

If you run unstable, then you can install it via apt:

# apt-get update
# apt-get install lighttpd lighttpd-doc

See http://packages.debian.org/unstable/web/lighttpd for current package details.

Norwegian step-by-step guide: http://www.delay.no/blog/index.php/oppsett-av-lighttpd-med-php5-cgi/

Compiling from Source

For compiling from source you need some more packages:

  • the headers for libpcre
  • and zlib

You have to make sure that the pcre and zlib is installed including their headers. The configure script will check them and will tell you if not. If everything is in place, you can compile lighttpd.

$ wget http://www.lighttpd.net/download/lighttpd-1.3.15.tar.gz
$ gzip -cd lighttpd-1.3.15.tar.gz | tar xf -
$ cd lighttpd-1.3.15

(install everything under /usr/local/)
$ ./configure 
$ make
$ make install

If mod_rewrite is marked as disabled after running configure, double check the configure output and see if PCRE (perl regular expression library) was detected ok.

Compiling from Packaged Source

RPM

$ yum install pcre-devel
$ yum install zlib-devel     
$ wget http://www.lighttpd.net/download/lighttpd-1.3.15-1.src.rpm
$ rpmbuild --rebuild lighttpd-1.3.15-1.src.rpm

(the path where the build package is located can be seen)
(a few lines above in the output of rpmbuild)
$ rpm -Uhv /usr/src/packages/RPMS/i386/lighttpd-1.3.15-1.i386.rpm

Debian

$ apt-get install libpcre3-dev
$ apt-get install zlib1g-dev

Since lighttpd 1.4.8 the debian/ directory was removed to simplify the inclusion into Ubuntu and Debian. If you want to build your own debian package take the debian/ dir from a older release and update the debian/changelog and follow the steps below:

$ wget http://www.lighttpd.net/download/lighttpd-1.4.7.tar.gz
$ wget http://www.lighttpd.net/download/lighttpd-1.4.8.tar.gz
$ gzip -cd lighttpd-1.4.7.tar.gz | tar xf -
$ gzip -cd lighttpd-1.4.8.tar.gz | tar xf -
$ cp -R lighttpd-1.4.7/debian lighttpd-1.4.8/
$ cd lighttpd-1.4.8
$ vi debian/changelog

( update the changelog entry to point to 1.4.8)
$ dpkg-buildpackage
$ cd ..
$ dpkg -i lighttpd-1.4.8-1.i386.deb

Note: Ubuntu users will need to "apt-get install dpkg-dev" to be able to use dpkg-buildpackage.

french translation here: http://meister.intuxication.org/~meister/dotclear/index.php?2006/08/18/29-faire-un-deb-de-lighthttpd

Compiling from SVN

svn://svn.lighttpd.net/lighttpd/trunk/

If you are compiling from SVN and you get warnings like this one "configure.in: 11: automake requires AM_CONFIG_HEADER', not `AC_CONFIG_HEADER'" make sure you have installed automake1.8 and make sure autogen.sh is using that automake binary (I also had automake1.4 installed).

Compiling v1.5(trunk) from SVN

Since the 1.5 branch scons has been replaced with cmake. From the top-level directory execute (adjust -D parameters to suit):

$ rm CMakeCache.txt
$ cmake -D WITH_BZIP:BOOL=ON -D WITH_LIBAIO:BOOL=ON -D WITH_LIBFCGI:BOOL=ON -D WITH_LUA:BOOL=ON -D WITH_OPENSSL:BOOL=ON -D WITH_SQLITE3:BOOL=ON -L .
$ make

Gentoo

Lighttpd is available in the Portage tree. You can simply install it by running emerge lighttpd.

Please note: Don't neglect to set the proper USE flags for your lighty installation and all its dependencies. Take a look at the flags Portage would use by running emerge with the --pretend --verbose --tree options. This will pretend to install lighttpd and display some informative output, such as all USE flags and dependencies:

$ emerge -pvt lighttpd

If necessary, add your desired flags to /etc/portage/package.use. For example, if you want to emerge lighttpd with support for MySQL and PHP but without SSL, set the according USE flags:

$ echo "www-servers/lighttpd php mysql -ssl" >> /etc/portage/package.use

If you want to use the latest unstable version (if one is available in Portage), add the ~arch keyword to /etc/portage/package.keywords:

$ echo "www-servers/lighttpd ~x86" >> /etc/portage/package.keywords

Now go ahead and install lighttpd:

$ emerge lighttpd

For a more verbose guide and description of all supported USE flags, see HOWTO Lighttpd.

FreeBSD

FreeBSD has the ports and lighttpd is in this tree for a long time now.

# cd /usr/ports/www/lighttpd
# make install clean

# cd /usr/ports/lang/php5/
# make install clean

Make sure you enable FastCGI support in the configuration dialog. If you don't get the configuration dialog, do "make config" first. The additional CONFIG_ARGS for the PHP5 installation force cgi-fcgi support in /usr/local/bin/php. The option '--with-pcre-regex' is needed to support several functions that use regular expressions like 'preg_match'.

php -v should give you something like this:

PHP 5.2.5 with Suhosin-Patch 0.9.6.2 (cli) (built: Dec  8 2007 05:47:06)
Copyright (c) 1997-2007 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies

PHP extensions are in /usr/ports/lang/php5-extensions/. If you need mySQL support, that is where you can find it, select only extensions that you actually need. During compiling when it asks you to install UTF8 support, I suggest you install it.

# cd /usr/ports/lang/php5-extensions
# make config
# make install clean

Now that everything is installed, enable Lighttpd in rc.conf and edit it's configuration:

# echo lighttpd_enable=\"YES\" >> /etc/rc.conf
# cd /usr/local/etc/
# cp lighttpd.conf.sample lighttpd.conf
# cp php.ini-recommended php.ini

You will probably need to create some directories and files, since the port neglects to do them for you (as of 2008 February 24):

# mkdir /var/log/lighttpd
# touch /var/log/lighttpd/lighttpd.error.log
# touch /var/log/lighttpd/lighttpd.access.log

Make your new directories and files accessible by the user and group "www" that Lighttpd operates as:

# chown www:www /var/log/lighttpd
# chown www:www /var/log/lighttpd/lighttpd.error.log
# chown www:www /var/log/lighttpd/lighttpd.access.log

Edit lighttpd.conf to use the new directories and files as follows:

  • server.errorlog = "/var/log/lighttpd/lighttpd.error.log"
  • accesslog.filename = "/var/log/lighttpd/lighttpd.access.log"

Edit lighttpd.conf docroot:

  • server.document-root = "/usr/local/www/"

Test to make sure Lighttpd starts up properly:

# /usr/local/etc/rc.d/lighttpd start

If you need to, you may shutdown lighttpd this way:

# /usr/local/etc/rc.d/lighttpd stop

And then restart it with this:

# /usr/local/etc/rc.d/lighttpd restart

If you get an error that says "permission denied", check to make sure that the files and directories mentioned exist AND that user www has permission to operate on them. Also be sure that lighttpd.conf has been corrected from the non-working default version. If you get no errors, put an HTML file in /usr/local/www/ and try to load it up in your browser. If everything works, now enable PHP:

  • In section "server.modules" uncomment the line "mod_fastcgi"
  • uncomment the entire section "fastcgi.server"
  • add the following lines under "socket" in the "fastcgi.server" section:
 "bin-path" => "/usr/local/bin/php-cgi",
 "broken-scriptfilename" => "enable"

Now make some more files and directories that are missing from the port (as of 2008 Feb 29):

# mkdir /var/run/lighttpd
# touch /var/run/lighttpd/php-fastcgi.socket

Make your new directories and files accessible by the user and group "www" that Lighttpd operates as:

# chown www:www /var/run/lighttpd
# chown www:www /var/run/lighttpd/php-fastcgi.socket

For more information on setting up PHP with Lighttpd, see TutorialLighttpdAndPHP and Docs:ModFastCGI .

Compiling from SVN

If you want to compile lighttpd from SVN on FreeBSD (at least for 6.1-RELEASE and probably below and possibly above) and already have GNU autoconf 2.59 and GNU automake 1.9 installed from ports, the easiest way is to run the commands that autogen.sh runs for you manually. The program names are different and the aclocal call needs to be changed a bit for it to work.

The following should work fine:

$ libtoolize
$ aclocal19 --copy --force -I /usr/local/share/aclocal
$ autoheader259
$ automake19 --add-missing --copy
$ autoconf259

The reason for this is that when you install automake 1.9 from ports it creates aclocal19, automake19 and corresponding dirs, but libtool and the like install their m4 scripts into /usr/local/share/aclocal which is not by default checked by aclocal19.

Ubuntu

Ubuntu requires you to install several development libraries before compiling.

$ sudo apt-get install libpcre3-dev
$ sudo apt-get install zlib1g-dev
$ sudo apt-get install libglib2.0-dev

Optional:

(If you want linux-libaio to be enabled, you need to)
$ sudo apt-get install libaio-dev
(For compress-bzip2)
$ sudo apt-get install libbz2-dev

Continue with the generic instructions.

Others

For all other platform, you have to make sure that the pcre and zlib are installed, including their headers. The configure script will check them and will tell you if not. If everything is in place, you can compile lighttpd.

$ wget http://www.lighttpd.net/download/lighttpd-1.3.15.tar.gz
$ gzip -cd lighttpd-1.3.15.tar.gz | tar xf -
$ cd lighttpd-1.3.15

(check configure options with './configure --help')
(install everything under /usr/local/)
$ ./configure 
$ make
$ make install

If mod_rewrite is marked as disabled after running configure, double check the configure output and see if PCRE (perl regular expression library) was detected ok.

Installing services

Lighttpd is meant to run in the background as daemon. You can either use the well known init-scripts or "supervise" to control it.

init scripts

The init-script that is shipped with the source-tarball is meant to be run on a LSB conforming platform like SuSE, Fedora or Debian.

$ sed -e 's/FOO/lighttpd/g' doc/rc.lighttpd > /etc/init.d/lighttpd
$ chmod a+rx /etc/init.d/lighttpd
$ cp -p doc/sysconfig.lighttpd /etc/sysconfig/lighttpd
$ install -Dp ./doc/lighttpd.conf /etc/lighttpd/lighttpd.conf
$ chkconfig lighttpd on

If you're running CentOS (or RHEL) you might need to change the first line to this

$ sed -e 's/FOO/lighttpd/g' doc/rc.lighttpd.redhat > /etc/init.d/lighttpd

In Debian\Ubuntu you use update-rc.d rather than chkconfig:

$ sudo update-rc.d lighttpd defaults

supervise

The supervise install is described in LighttpdUnderSupervise

More

Before you can run lighttpd you have to update the configfile that you just copied to /etc/lighttpd/lighttpd.conf