Old version 1.4.xx has mod_fastcgi for PHP. This module has been replaced by mod_proxy_backend_fastcgi and mod_proxy_core in Lighttpd 1.5.xx.

FastCGI was developed by FastCGI and is a binary container around HTTP requests which reduces the parsing overhead.

FastCGI used for both PHP and rails application. In this small howto I will explain howto configure PHP under Lighttpd 1.5.xx.

Required softwares

[a] Make sure you have Lighttpd v1.5.xx installed [b] spawn-fcgi binary (part of lighttpd software) to spawns fastcgi processes. It is used to spawn remote/local FastCGI processes such as PHP or ruby. [c] PHP compiled / installed as fastcgi. Type the following command to verify that php is installed as fastcgi binary (look for cgi-fcgi word):
$ php-cgi -v
$ php -v
PHP 5.1.6 (cgi-fcgi) (built: Mar  9 2007 07:25:36)
Copyright (c) 1997-2006 The PHP Group
Zend Engine v2.1.0, Copyright (c) 1998-2006 Zend Technologies

mod_proxy_backend_fastcgi configuration

Open configuration file /etc/lighttpd/lighttpd.conf
# vi /etc/lighttpd/lighttpd.conf
Make sure following modules are loaded:
server.modules += ( "mod_proxy_core", "mod_proxy_backend_fastcgi" )

Configure fastcgi PGP module by appending following configuration directives:

$HTTP["url"] =~ "\.php$" {
        proxy-core.balancer = "round-robin"
        proxy-core.allow-x-sendfile = "enable"
        proxy-core.check-local = "enable"
        proxy-core.protocol = "fastcgi"
        proxy-core.backends = ( "unix:/tmp/php-fastcgi.sock" )
        proxy-core.max-pool-size = 16

Save and close the file.

Task: Start lighttpd

Type the following command to swap php using spawn-fcgi:
# /usr/bin/spawn-fcgi -s /tmp/php-fastcgi.sock -f /usr/bin/php-cgi -u lighttpd -g lighttpd -C 5 -P /var/run/spawn-fcgi.pid

Start/restart lighttpd:
# /etc/init.d/lighttpd start

Task: Stop lighttpd

Type the following command:
# /etc/init.d/lighttpd stop
Kill external php process:
# killall php-cgi

Task: Patch lighttpd init startup script

Since lighttpd uses external binary to swap php or ruby application you need to add stop and start functionality by patching /etc/init.d/lighttpd file. You can grab my /etc/init.d/lighttpd file .
# cd /etc/init.d/
# mv lighttpd lighttpd.old
# wget http://www.cyberciti.biz/files/lighttpd/1.5.0/lighttpd.init.d.txt
# mv lighttpd.init.d.txt lighttpd
# chmod +x lighttpd

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 10 comments so far... add one

CategoryList of Unix and Linux commands
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
10 comments… add one
  • Hany el-Kerdany Sep 9, 2009 @ 21:43

    Just wanted to mention that PHP 5.3 has fcgi enabled by default, and the output of the “php -v” command won’t containg the “cgi” word ..

  • killerBird Sep 8, 2009 @ 22:45

    After following all the steps when i am trying to start lighttpd its showing me this error:
    Can’t open /etc/rc.d/init.d/functions

    any clue wil be very much appreciated , please

  • b2d Jun 10, 2009 @ 11:44

    Very usefull … greate thanx but I found /etc/init.d/spawn-cgi
    edited it and got the result!

  • Totiz May 18, 2009 @ 16:25

    Thank you for apwn-fcgi command.
    I was install Lighttpd 1.5 and get problem with php engine.
    After apwan-fcgi I can run .php file.

  • Fujiko Fujio Nov 3, 2008 @ 4:12

    Thanks for this very informative tutorial, I was able to compile and get lighttpd 1.5.0 running but I’m having a problem with the init script to run spawn-fcgi and lighttpd automatically. I’m using ubuntu 8.10 and the script that you have does not seem to work.

    Can you please provide instructions on how I can configure lighttpd on ubuntu and also using virtual host.

    Thanks 🙂

  • Todd Mar 20, 2008 @ 6:24

    Thanks for the spawn-fcgi tips! This was a lifesaver.

    Included it in my post about setting up uploaders with lighttpd here:

    Lighttpd 1.5 and PHP (Uber-Uploader too)

  • AD Dec 1, 2007 @ 16:04

    good job dude, just upgraded today from 1.4.18 to 1.5 and was surprise to see the fastCGI system fuly rewrote, but finnally that’s better I no more have to use the 3rd party tool execwrap now because spawn-cgi does the job, thanks for the nice page dude, already ready for 1.5.x by your help 😉

  • jim Nov 3, 2007 @ 22:07


  • gregf Apr 7, 2007 @ 22:00

    Ah, nice work. I’ll have to play with this once 1.5x comes out officially. Bookmarked till then.

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Problem posting comment? Email me @ webmaster@cyberciti.biz