Personal tools
You are here: Home GNU / Linux Debian 4.0 Etch Install Lighttpd and PHP 5 on Debian 4.0 Etch and 5.0 Lenny
Document Actions
  • Send this page to somebody
  • Print this page
  • Add Bookmarklet

Install Lighttpd and PHP 5 on Debian 4.0 Etch and 5.0 Lenny

by Pierre-Yves Landuré last modified 2010-11-16 08:45

Lighttpd is a very light HTTP server. It is also very easy to configure it. It is a very interesting alternative to Apache when you want to reduce your memory usage. This article explain how to install Lighttpd with PHP 5 enabled.

Install

First, we install the need packages :

apt-get install lighttpd libterm-readline-gnu-perl php5-cgi

By default, on Debian 4.0 Etch, Lighttpd is installed with a configuration using php4-cgi. In the case where this is the distribution we use, we apply the needed patch :

if [ ! -z "$(/bin/grep '/usr/bin/php4-cgi' /etc/lighttpd/conf-available/10-fastcgi.conf)" ]; then
/bin/cp /etc/lighttpd/conf-available/10-fastcgi.conf /etc/lighttpd/conf-available/10-fastcgi-php5.conf
/bin/sed -i -e 's/php4/php/g' /etc/lighttpd/conf-available/10-fastcgi-php5.conf
fi

We enable the correct configuration depending if we use Debian 4.0 Etch or Debian 5.0 Lenny :

if [ -e /etc/lighttpd/conf-available/10-fastcgi-php5.conf ]; then
/usr/sbin/lighty-enable-mod fastcgi-php5
else
/usr/sbin/lighty-enable-mod fastcgi
fi

And we reload the LigHTTPd configuration :

/etc/init.d/lighttpd force-reload

Going deeper

Enhancing PHP performances

If you want, you can install a PHP accelerator by following my guide Install XCache on Debian 4.0 Etch.

Creating a Virtual Host with Lighttpd

Like Apache, Lighttpd can manage several web sites on one server. Here is a way to quickly create a virtual host serving a folder.

First,  please specify the hostname for your virtual host (replace the bold value):

SITE_HOSTNAME=www.my-domain.com

Now, specify the folder that you want to assign to this hostname (replace the bold value):

SITE_PATH=/var/www/www.my-domain.com/

Once this done, download the virtual host configuration template:

SITE_CONF=$(/bin/echo ${SITE_HOSTNAME} | /bin/sed -e 's/\./-/g')
/usr/bin/wget http://howto.landure.fr/gnu-linux/debian-4-0-etch/installer-lighttpd-et-php-sur-debian-4-0-etch/lighttpd-vhost.conf \
--output-document=/etc/lighttpd/conf-available/20-${SITE_CONF}.conf

Apply your settings to this template:

/bin/sed -i -e "s/SITE_HOSTNAME/${SITE_HOSTNAME}/g" \
-e "s|SITE_PATH|${SITE_PATH}|g" \
/etc/lighttpd/conf-available/20-${SITE_CONF}.conf

Enable the configuration you have just created:

/usr/sbin/lighty-enable-mod ${SITE_CONF}

Test the new configuration:

/usr/sbin/lighttpd -t -f /etc/lighttpd/lighttpd.conf

If you see no error, reload the Lighttpd configuration:

/etc/init.d/lighttpd force-reload

You should now be able to visit your website.

Note : Using virtual host with Lighttpd is usefull, even if you use Lighttpd behind a Apache reverse proxy. If you are doubtfull, take a look at the ProxyPreserveHost option of the Apache mod_proxy.

URL Rewriting with Lighttpd

Unlike Apache 2, Lighttpd is no able to make complex URL rewrites. However, there is a way to do simple URL rewriting with some web applications like Wordpress or Symfony projects. You only need to configure the index.php file of these web applications to handle the 404 errors.

In order to do this, simply add the following line to the configuration file of the virtual host serving your web application, and change the path to the index.php file to fit the application location:

server.error-handler-404 = "/index.php"

See also

Attachments

Group and User lighttpd

Posted by Orlando Agostinho at 2008-09-23 13:33
Hi,


Very good tutorial! Congratulations!

Can you explain little bit about group and user for Lighttpd?

Thanks!

a domain name with "www" prefix

Posted by thinkweird at 2009-05-18 01:22
This guide works flawlessly.

I have one question about virtual domains:

you only mentioned virtual sites with 'www' prefix, but how to configure the same site without 'www' prefix for the same site?

Now I am making two configuration files with 'www' and without 'www' for the same site, but it does appear redundant, doesn't it?

virtualhost with lighty

Posted by Lone Wolf at 2009-05-18 04:08
Lighty support regular expressions to match domain names. To enable this feature, use =~ instead of == to match the domain. For example :


$HTTP ["host"] =~ "(www.)?domain.com" {

Hope this help

need mod_simple_vhost?

Posted by ol at 2010-05-26 03:50
I keep referring back to this page for setting up lighty on Debian and it works very well.

There is one question: in the configure file for virtual hosting, do I need this line? 

server.modules += ( "mod_simple_vhost" )

It seems the virtual host works ok even without this line. What is it for? Enabling simple_vhost module?

Also, to avoid the www prefix problem, lighty wiki gives this solution:

$HTTP["host"] =~ "(^|\.)example\.com$" {
...
}

and it worked as well as you suggested in the reply above.

simple_vhost

Posted by Lone Wolf at 2010-05-26 07:30
Yes the server.modules line is used to enable the simple_vhost module, in case it is not already enabled. I think it is better to have virtual hosts embeding their dependencies.

BlogBang
Navigation
 

Powered by Plone CMS, the Open Source Content Management System

This site conforms to the following standards:

Wikio