Zen-Dreams

Zen-Dreams.com

[Linux] Lighttpd webserver

  • Français

In the world of open source web servers, you mostly talk about Apache, but the problem with Apache is that for development, it’s quite heavy and slower than other alternatives, such as Lighttpd. Even if in Lighttpd there is the word light, it doesn’t mean that it comes with fewer features. In fact, it’s far from the truth as light only stands for the small memory footprint and speed for static page serving.

Here is a list of some features available with Lighttpd :

Virtual hosts
Virtual directory listings
URL-Rewriting, HTTP-Redirects
Large File Support (64bit fileoffsets)
on-the-fly output-compression with transparent caching
deflate, gzip, bzip2
authentication : basic, digest
backends: plain files, htpasswd, htdigest, ldap
fast and secure application controlled downloads
Server Side Includes
User Tracking
FastCGI, CGI, SSI
Same speed as or faster than apache + mod_php4
Includes a utility to spawn FastCGI processes (neccesary for PHP 4.3.x) via FastCGI and CGI interface
load-balanced FastCGI (one webserver distibutes request to multiple PHP-servers via FastCGI)
chroot(), set UID, set GID
protecting docroot
strict HTTP-header parsing

Pure happiness for sysadmins and web developers. Lots of websites are already using it in a way or another, like YouTube, Wikipedia or even sourceforge.net.

Enough with the talk, let’s move to the installation, I’ll talk of the installation under Ubuntu, which is one of the most popular GNU/Linux distribution, and also the one that I personally use.

The first step is to install the packages using the apt-get command :

sudo apt-get install lighttpd lighttpd-doc libpcre3

Here you are, with your brand new Lighttpd installed. If with that installation you need to use mysql and php, you have to install these packages : mysql-common, libmysqlclient12, php5-cgi and even mysql-server if you need to host the database on the same server

In case you want to use php5, you need to activate the fastCGI module by issuing the following commands in a terminal:

sudo ln -s /etc/lighttpd/conf-available/10-fastcgi.conf /etc/lighttpd/conf-enabled/10-fastcgi.conf

sudo /etc/init.d/lighttpd restart

Here you go, you have your lighttpd installed with php5 alongside.

Now, all you have remaining to do is to change your settings according to your needs. To do so, my advice would be to browse the official documentation here. Or even better, ask me in the comments here and I’ll try to answer as soon as possible.

By Anthony

4 Comments

  1. Gauthier
    Posted 23 April 2008 at 13:48 | Permalink

    Bonjour,

    Je me sers de lighttpd sur un réseau local, et effectivement, il me donne toute satisfaction.

    Il a les défauts de ses qualités: un seul fichier de configuration, peut-être simple à maintenir, mais ce qui veut dire que les règles de réécritures ne peuvent figurer comme avec Apache dans des fichiers .htaccess dispersés dans l’arborescence. Et donc qu’il ne convient pas à un hébergement mutuallisé où les utilisateurs souhaiteraient personnaliser le comportement du serveur pour leur site.

    Et j’avoue n’avoir jamais rien compris à la façon d’activer l’exécution de scripts cgi avec l’identité de l’utilisateur…

    Si vous aviez des pistes à ce sujet, elles seraient bienvenues ;-)

    Cordialement,

    Gauthier

  2. Posted 24 April 2008 at 8:59 | Permalink

    Gauthier,

    Tu n’es pas obligé de n’avoir qu’un seul fichier de configuration, tout comme dans Apache tu peux inclure d’autres fichiers de conf.
    Tu peux aussi utiliser des .htaccess dans les dossiers utilisateurs.
    J’imagine que des sites comme wikipedia ne se contentent pas d’un seul fichier de configuration et pourtant ils utilisent Lighttpd.

    Dès que j’aurais le temps, je ferais un petit article pour expliquer comment rendre modulaire le fichier de conf, mais toujours est-il que dans la documentation tu doit pouvoir trouver cela.

    Sinon, si tu veux executer les scripts CGI avec un autre utilisateur que celui qui execute le serveur tu as execwrap qui permet cela. Si la question est de faire tourner lighttpd avec un autre user, l’option est clairement ecrite dans la doc :
    server.username: username used to run the server.

  3. Gauthier
    Posted 24 April 2008 at 14:28 | Permalink

    Re-bonjour,

    Avec suexec, Apache permet que les scripts cgi exécutés dans les répertoires utilisateurs (http://localhost/~toto) le soient avec les droits de ces utilisateurs. Ce qui permet d’écrire/effacer dans des répertoires dont les droits ne sont pas à 777, et d’éviter que les scripts ne créent des fichiers avec l’uid de nobody:nogroup, qu’un utilisateur non-privilégié ne pourrait modifier.

    Pour autant que Apache et suexec soient bien configuré, il suffit donc qu’un utilisateur ait un répertoire web (généralement ~/public_html) pour que tout y fonctionne.

    Honnêtement, ce que j’ai lu dans la doc de lighttpd pour y parvenir m’a complêtement découragé. Si j’ai bien compris, dans le meilleur des cas, il faut configurer un hôte virtuel, un “wrapper” et un processus fast-cgi pour chaque utilisateur… J’ai abandonné.

  4. Posted 24 April 2008 at 17:52 | Permalink

    Effectivement, mettre en place l’équivalent de suexec ne semble pas simple sous lighttpd, il faudrait que je me penche un peu sur ce problème…

Post a Comment

Your email is never shared. Required fields are marked *

*
*