≡ Menu

Red Hat enterprise Linux Install lighttpd and Fastcgi PHP

Lighttpd logo

I have received many queries regarding how to configure and install Lighttpd web server under Red Hat Enterprise Linux version 4.0. Mark asks:

RHEL 64 bit v4.0 does not support PHP as FastCGI. Lighttpd is not available from RHN (up2date command). How do I configure and install lighttpd with FastCGI?

Ok let me answer these questions and other queries systematically. I have installed Lighttpd under both RHEL v4.0 32/64 bit version couple of times. In all cases, you need to compile both PHP and Lightttpd. Do not worry steps are quite easy.

Install and configure Lighttpd under RHEL

RedHat Linux use RHN to provide stable version of all software(s) including PHP/Apache and for some weird reasons it does not come with lighttpd web server. However, I have tested RHEL v.5.0 (beta) which comes with lots of goodies such as caching software, fastcgi etc.

Step #1: Install and configure Lighttpd under RHEL 64 bit v4.0

First, you need to remove installed PHP version. Use rpm -qa | grep php command to find out list of all installed PHP rpm files:
# rpm -qa | grep phpRemove all PHP files:# rpm -e php php-devel php-imap php-ldap php-pear

Step #2: Download lighttpd source code

There is no official RPM file available from Red Hat itself for 64/32 bit version. You can download and compile Lighttpd as follows:
# wget http://lighttpd.net/download/lighttpd-1.4.16.tar.gz
# tar -zxvf lighttpd-1.4.16.tar.gz
# cd lighttpd-1.4.16

Step #3: Compile and install lighttpd:

Following commands will compile lighttpd with OpenSSL support. First, configure lighttpd:
# ./configure --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

Now compile lighttpd
# make

Install lighttpd:
# make install

Step #4: Build PHP RPM as FastCGI

Now recompile PHP and build PHP RPM as FastCGI. Download PHP SRPM from official Red Hat Site or use following command to download PHP source RPM (recommended):
# cd /opt
# up2date -d --src php

Now install downloaded source RPM file:
# rpm -ivh php-4.3.9-3.1.src.rpm

First, install all necessary development libraries:
# up2date aspell-devel libjpeg-devel libpng-devel libc-client-devel mysql-devel postgresql-devel unixODBC-devel net-snmp-devel elfutils-devel libxslt-devel freetype-devel

Open php rpm configuration file:
# cd /usr/src/redhat/SPECS/
Open php.spec file:
# vi php.spec
Find out line, which read as follows:

Before that line add:
--enable-fastcgi \
Save and close the file.

Compile and build RPM file:
# rpmbuild -bb php.spec

Now install all newly rebuild RPM files. Go to /usr/src/redhat/RPMS/x86_64 directory, where all newly build RPMs are stored:
# cd /usr/src/redhat/RPMS/x86_64
# rpm -ivh php-4.3.9-3.18.x86_64.rpm php-gd-4.3.9-3.18.x86_64.rpm php-imap-4.3.9-3.18.x86_64.rpm php-mysql-4.3.9-3.18.x86_64.rpm php-mbstring-4.3.9-3.18.x86_64.rpm php-pear-4.3.9-3.18.x86_64.rpm

Make sure php is installed with fastcgi:
# php -vOutput:

PHP 4.3.9 (cgi-fcgi) (built: Oct  2 2006 15:31:07)
Copyright (c) 1997-2004 The PHP Group
Zend Engine v1.3.0, Copyright (c) 1998-2004 Zend Technologies

If you do not have development environment installed or if you are too lazy to compile download AMD x86_64 RPM files. Please note that these files are provided as it is.

Basic Lighttpd configuration

a) Add a lighttpd user
# adduser -s /sbin/nologin lighttpd

b) Create a lighttpd.conf file
# mkdir /etc/lighttpd
# cd /etc/lighttpd
# vi lighttpd.conf
Add following config code:
server.modules = (
"mod_accesslog" )
index-file.names = ( "index.php", "index.html",
"index.htm", "default.htm" )
mimetype.assign = (
".rpm" => "application/x-rpm",
".pdf" => "application/pdf",
".sig" => "application/pgp-signature",
".spl" => "application/futuresplash",
".class" => "application/octet-stream",
".ps" => "application/postscript",
".torrent" => "application/x-bittorrent",
".dvi" => "application/x-dvi",
".gz" => "application/x-gzip",
".pac" => "application/x-ns-proxy-autoconfig",
".swf" => "application/x-shockwave-flash",
".tar.gz" => "application/x-tgz",
".tgz" => "application/x-tgz",
".tar" => "application/x-tar",
".zip" => "application/zip",
".mp3" => "audio/mpeg",
".m3u" => "audio/x-mpegurl",
".wma" => "audio/x-ms-wma",
".wax" => "audio/x-ms-wax",
".ogg" => "application/ogg",
".wav" => "audio/x-wav",
".gif" => "image/gif",
".jpg" => "image/jpeg",
".jpeg" => "image/jpeg",
".png" => "image/png",
".xbm" => "image/x-xbitmap",
".xpm" => "image/x-xpixmap",
".xwd" => "image/x-xwindowdump",
".css" => "text/css",
".html" => "text/html",
".htm" => "text/html",
".js" => "text/javascript",
".asc" => "text/plain",
".c" => "text/plain",
".cpp" => "text/plain",
".log" => "text/plain",
".conf" => "text/plain",
".text" => "text/plain",
".txt" => "text/plain",
".dtd" => "text/xml",
".xml" => "text/xml",
".mpeg" => "video/mpeg",
".mpg" => "video/mpeg",
".mov" => "video/quicktime",
".qt" => "video/quicktime",
".avi" => "video/x-msvideo",
".asf" => "video/x-ms-asf",
".asx" => "video/x-ms-asf",
".wmv" => "video/x-ms-wmv",
".bz2" => "application/x-bzip",
".tbz" => "application/x-bzip-compressed-tar",
".tar.bz2" => "application/x-bzip-compressed-tar"
########## BASE CONFIG - EDIT BELOW #########################
server.tag = "lighttpd (RedHat)"
accesslog.filename = "/var/log/lighttpd/access_log"
server.errorlog = "/var/log/lighttpd/error_log"
server.document-root = "/var/www/html/"
url.access-deny = ( "~", ".inc" )
static-file.exclude-extensions = ( ".php", ".pl", ".fcgi" )
server.port = 80
server.bind = "202.54.xxx.xxx"
server.error-handler-404 = "/errorr404.php"
server.pid-file = "/var/run/lighttpd.pid"
server.username = "lighttpd"
server.groupname = "lighttpd"
compress.cache-dir = "/tmp/lighttpd/cache/compress/"
compress.filetype = ("text/plain", "text/html")
$HTTP["url"] =~ "\.pdf$" {
server.range-requests = "disable"
fastcgi.server = ( ".php" =>
( "localhost" =>
"socket" => "/tmp/php-fastcgi.socket",
"bin-path" => "/usr/bin/php",
"max-procs" => 2,

c) Create a lighttpd sysconfig file:
# vi /etc/sysconfig/lighttpd
Add following line:
Save and close the file.

d) Create a lighttpd startup file (init.d script)
# vi /etc/init.d/lighttpd
Append following line:
# lighttpd Startup script for the lighttpd server
# chkconfig: - 85 15
# description: Lighttpd web server
# processname: lighttpd
# config: /etc/lighttpd/lighttpd.conf
# config: /etc/sysconfig/lighttpd
# pidfile: /var/run/lighttpd.pid
# Source function library
. /etc/rc.d/init.d/functions
if [ -f /etc/sysconfig/lighttpd ]; then
. /etc/sysconfig/lighttpd
if [ -z "$LIGHTTPD_CONF_PATH" ]; then
start() {
echo -n $"Starting $prog: "
daemon $lighttpd -f $LIGHTTPD_CONF_PATH
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog
return $RETVAL
stop() {
echo -n $"Stopping $prog: "
killproc $lighttpd
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog
return $RETVAL
reload() {
echo -n $"Reloading $prog: "
killproc $lighttpd -HUP
return $RETVAL
case "$1" in
if [ -f /var/lock/subsys/$prog ]; then
status $lighttpd
echo $"Usage: $0 {start|stop|restart|condrestart|reload|status}"
exit $RETVAL

Save and close the file.

e) Create necessary directories and set correct permissions:
# mkdir -p /var/log/lighttpd
# mkdir -p /tmp/lighttpd/cache/compress/
# chown lighttpd:lighttpd /var/log/lighttpd
# chown lighttpd:lighttpd /tmp/lighttpd/cache/compress/

f) Start the lighttpd, but first stop Apache if running:
# chkconfig httpd off
# /etc/init.d/httpd stop
# chkconfig --add lighttpd
# chkconfig lighttpd on
# /etc/init.d/lighttpd start

Verify that Lighttpd is running:
# netstat -tulpn | grep :80

Update: See how to use lighttpd and FastCGI configuration under RHEL 5.0 / CentOS 5.0.

Share this on:

{ 16 comments… add one }

  • javier wilson April 13, 2007, 5:28 am

    you also require http-devel to build php from source (src.rpm) in RHEL4.

  • Sunil May 24, 2007, 10:11 pm

    Hi all,

    I get this error message. Any thoughts?

    /etc/init.d/lighttpd start

    Starting lighttpd: /etc/rc.d/init.d/functions: line 148: /usr/sbin/lighttpd: No such file or directory

  • Eric July 13, 2007, 5:16 pm

    I’m curious about using the configuration settings on a system that has a standard yum installation with an earlier version of lighttpd. Would there be collisions? Would an update to yum overwrite this installation? I just haven’t found enough information, or experience, to decipher the configure options. Any help would be appreciated.


  • nixCraft July 13, 2007, 5:38 pm

    If you update lighttpd using yum, there should not be a problem. Don’t mix two different versions.

  • kuldeep July 31, 2007, 5:06 am

    i want latest update about red hat linux through my email id.

  • kuldeep July 31, 2007, 5:07 am

    good site for linux .

  • Ben Wallis August 29, 2007, 8:19 am

    I want to keep using Apache for hosting PHP sites and only use Lighttpd as a static media server.

    Does that mean that I don’t need to re-compile PHP?

  • nixCraft August 29, 2007, 8:31 am

    kuldeep, thanks for feedback.

    Ben, noop, php-cgi only needed if you need dynamic content and not for static content such as html or images.

  • Ben Wallis August 29, 2007, 9:24 am

    Thanks vivek. So I only need to do Step #3 to install Lighttpd on rhel4? As long as I don’t want to use Lighttpd for PHP?
    BTW this site is very useful, cheers!

  • nixCraft August 29, 2007, 9:55 am

    Yup, step # 3 and you need to configure lighttpd without fastcgi module / php.

  • Francisco December 13, 2007, 9:56 pm

    Hi.. first: ur site is great and very usefull. 2th this guide is work fine with me =)

    cheers from chile… sorry for my poor english

  • john victor March 26, 2009, 8:38 am

    hi everyone,

    i need your help.
    i want to create a website through lighthttpd.
    i have already installed lighthttpd. but i have no idea that how to create site in rhel5
    Please tell me how to create website in lighthttpd.

    Thanks and regards

  • ishan May 21, 2009, 12:35 pm

    Very nice site dude . . . fantastic ! keep to good work going !

  • dH June 25, 2009, 2:11 pm

    For lighttpd it’s easier to do:

    yum install lighttpd-fastcgi.x86_64 0:1.4.22-2.el5.rf

  • Alzea March 24, 2011, 7:38 am

    i got this error :

    [root@fedora lighttpd]# /etc/init.d/lighttpd start
    Starting lighttpd: 2011-03-24 14:38:27: (configfile.c.907) source: /etc/lighttpd/lighttpd.conf line: 326 pos: 49 parser failed somehow near here: include_shell

    How i can fix this? Thanks.

Leave a Comment

   Tagged with: , , , , , , , , , , ,