Polls

Topics

Installing and configuring lighttpd webserver - HOWTO

Posted by Vivek on Sunday July 2, 06 @5:13 pm

Lighttpd logo

lighttpd is a web server for UNIX/Linux and Windows operating systems. It is an alternative to Apache web server. It is also called Lighty.

It is designed to be secure, fast, standards-compliant, and flexible while being optimized for speed-critical environments. Its low memory footprint (compared to other web servers), light CPU load and its speed goals make lighttpd suitable for servers that are suffering load problems. Visit official site for more information.

This document shows you how to install lighttpd and covers basic configuration.

Installing lighttpd

If you are using RPM based distro (RedHat, Fedora and friends) download RPM and other formats here. Binary RPM is here

Download Fedora Core RPM Binary:

$ cd /tmp
$ wget http://lighttpd.net/download/lighttpd-1.4.13-1.i386.rpm
$ su -
# rpm -ivh lighttpd-1.4.13-1.i386.rpm

Now skip to configuration section.

Debian Linux user use apt-get command to install lighttpd:

# apt-get install lighttpd

Now skip to configuration section.

Source code installation

Above RPM binary does not carries mod_rewrite and other stuff, so I had decided to rebuild lighttpd from source code (note source code installation is recommended for advanced users only):
$ cd /tmp

Get latest source code:
$ wget http://lighttpd.net/download/lighttpd-1.4.13.tar.gz

Untar tar ball:
$ tar -zxvf lighttpd-1.4.13.tar.gz
$ cd lighttpd-1.4.13

Configure lighttpd with ./configure

$ ./configure --host=i686-redhat-linux-gnu \
--build=i686-redhat-linux-gnu \
--target=i386-redhat-linux \
--program-prefix= --prefix=/usr \
--exec-prefix=/usr \
--bindir=/usr/bin \
--sbindir=/usr/sbin \
--sysconfdir=/etc \
--datadir=/usr/share \
--includedir=/usr/include \
--libdir=/usr/lib \
--libexecdir=/usr/libexec \
--localstatedir=/var \
--sharedstatedir=/usr/com \
--mandir=/usr/share/man \
--infodir=/usr/share/info \
--with-openssl \
--with-pcre \
--with-zlib \
--with-bzip2 \
--disable-ipv6 \
--with-PACKAGE=mod_redirect \
--with-rewrite \
--with-redirect \
--with-ssi

Above configure option includes support for SSL, mod_rewrite, ssi, mod_redirect etc. Run following command to get help on all other available options:
$ ./configure --help | less

Install lighttpd:
$ make
# make install

Create a configuration directory:
# mkdir /etc/lighttpd/

Create lighttpd user and group:
# groupadd lighttpd
# useradd -g lighttpd -d /var/www/html -s /sbin/nologin lighttpd

OR
# adduser -g lighttpd -d /var/www/html -s /sbin/nologin lighttpd

Create a log directory:
# mkdir /var/log/lighttpd
# chown lighttpd:lighttpd /var/log/lighttpd

Download sample config and startup files:
# cd /etc/lighttpd
# wget http://www.cyberciti.biz/tips/wp-content/uploads/2006/07/lighttpd.conf.txt
# mv lighttpd.conf.txt lighttpd.conf
# chown lighttpd:root /etc/lighttpd/lighttpd.conf
# cd /etc/init.d/
# wget http://www.cyberciti.biz/tips/wp-content/uploads/2006/07/lighttpd.txt
# mv lighttpd.txt lighttpd
# chmod +x lighttpd

Configuring lighttpd

Following are important files for lighttpd server:

These files are installed by default for all binary installations methods. Now lighttpd installed and it is time to configure lighttpd.

Remove apache

If you are not going to use Apache v1.3/2.x at all, then it is better to remove it (make sure you have a backup of Apache data and config file):
# rpm -e httpd
# yum remove httpd
# apt-get remove apache2

Understanding core lighttpd Directives

Following are core lighttpd Directives:

server.modules = (
"mod_access",
"mod_accesslog",
"mod_fastcgi",
"mod_rewrite",
"mod_auth"
)
: Above modules are loaded by lighty:

mimetype.assign = (
".pdf" => "application/pdf",
".sig" => "application/pgp-signature"
)
: Use to setup mimetype mapping.

Open file /etc/lighttpd/lighttpd.conf and setup all of the above directives:
# vi /etc/lighttpd/lighttpd.conf

Save the file and start the lighttpd:
# /etc/init.d/lighttpd start

Verify that lighttpd is running:
$ netstat -ntulp

Output:

Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name
tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      29855/sshd
tcp        0      0 203.111.103.81:80           0.0.0.0:*                   LISTEN      5866/lighttpd
...
.....
..

Fire your web browser and test new setup by typing URL: http://your-domain.com/ or http://server-ip/

Next time I will cover following topics:

Lighttpd How to

Lighttpd security

Lighttpd software configuration how-tos

Lighttpd Server Monitoring

Lighttpd Troubleshooting

Download: Lighttpd Sample config and RPM files

This is regularly updated series. Last Updated on 10-Dec-2006 by nixCraft.

Want to stay up to date with the latest Linux tips, news and announcements? Subscribe to our free e-mail newsletter or full RSS feed to get all updates. You can Email this page to a friend.

You may also be interested in...

Discussion on This Article:

  1. Srinivasan R Says:

    I would really like to know how to setup cgi-bin and to execute cgi applications in lighttpd.

  2. nixcraft Says:

    Add mod_cgi to server.modules i.e following command:
    server.modules += ( “mod_cgi” )

    Add alias url:
    alias.url += ( “/cgi-bin/” => “/var/www/cgi-bin/” )

    Add following url:
    $HTTP["url"] =~ “/cgi-bin/” {
    cgi.assign = ( “.pl” => “/usr/bin/perl” )
    }

    I will cover detailed article later on

  3. Gerard Says:

    About ./configure:
    I really doubt you would need all those options, configure can figure them out itself, for example –host=i686-redhat-linux-gnu or all those directories.

  4. nixcraft Says:

    You can skip following
    –build=i686-redhat-linux-gnu \
    –target=i386-redhat-linux \

    But rest is required to make sure /etc/init.d/lighttpd and other scripts find them.

  5. LavaLamp Says:

    Hi!

    This is an excellent collection. I would like to see more tutorials and configuration howtos - Rub on Rails and Python lighttpd configuration.

    Thanks for all wonderful tutorials.

  6. TECK Says:

    Hi nixcraft,

    I was wondering if you could look the RPM I built on CentOS5 and tell mw what I did wrong:
    fbytes.com/lighttpd-1.4.15-1.src.rpm

    For some reason, the memcache option is disabled.
    If I use the 1.4.13 archive everything is ok, so I believe is lighty bug.

    Thanks for your help.

  7. Premkumar Says:

    Hi,

    This tutorial is very helpful for my team. Thanks a lot…..

  8. kunal Says:

    This tutorial is very helpful for me.

    Thanks a lot !!!!!!!!!

  9. Madhavi Says:

    Hi,

    Can we write cgi-bin programs in C and run on lighttpd??

  10. vivek Says:

    Yes you can write program in c/c++ and run as cgi-bin

  11. harish Says:

    Hi,
    this is really nice tutorial and seriously help me a lot but anyone can tell how can i remove flowplayer logo from my fullscreen mode ????

Leave a Reply

We encourage your comments, and suggestions. But please stay on topic, be polite, and avoid spam. Thank you very much for stopping by our site!

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

~ Last updated on: December 9, 2006

Copyright © 2004-2008 nixCraft. All rights reserved - TOS/Disclaimer - Privacy policy - Sitemap - Powered by Open source software.