≡ Menu

Lighttpd PHP fastcgi configuration

Lighttpd logo

FastCGI is a language independent, scalable, open extension to CGI that provides high performance without the limitations of server specific APIs. FastCGI provides better scalability and performance. Instead of creating a new process (the CGI program) for every request, FastCGI uses a single persistent process which handles many requests over its lifetime. (See wikipedia article for more information)

Make sure php support fastcgi

Type any one of the following command to verify that php support fastcgi
$ php -v


PHP 5.0.4 (cli) (built: Nov  8 2005 08:27:12)
Copyright (c) 1997-2004 The PHP Group
Zend Engine v2.0.4-dev, Copyright (c) 1998-2004 Zend Technologies

$ php-cgi -v

PHP 5.0.4 (cgi-fcgi) (built: Nov  8 2005 08:25:54)
Copyright (c) 1997-2004 The PHP Group
Zend Engine v2.0.4-dev, Copyright (c) 1998-2004 Zend Technologies

You must get string cgi-fcgi. Next find out full path to php-cgi or php binary:
$ which php-cgi


Open lighttpd configuration file:
# vi /etc/lighttpd/lighttpd.conf

First add the module mod_fastcgi (lighttpd provides an interface to a external programs that support the FastCGI interface via this module). Make sure your server.modules loades mod_fastcgi:

server.modules              = (

Now add following lines to configuration:

fastcgi.server = ( ".php" => ((
                     "bin-path" => "/usr/bin/php-cgi",
                     "socket" => "/tmp/php.socket"

Save the configuration and close all the files. Restart the lighttpd:
# /etc/init.d/lighttpd restart

Test your configuration by running php program or application.

See also

Share this on:

Your support makes a big difference:
I have a small favor to ask. More people are reading the nixCraft. Many of you block advertising which is your right, and advertising revenues are not sufficient to cover my operating costs. So you can see why I need to ask for your help. The nixCraft, takes a lot of my time and hard work to produce. If you use nixCraft, who likes it, helps me with donations:
Become a Supporter →    Make a contribution via Paypal/Bitcoin →   

Don't Miss Any Linux and Unix Tips

Get nixCraft in your inbox. It's free:

{ 21 comments… add one }
  • Pierre July 3, 2007, 10:41 am

    There is an typo in:
    fastcgi.server = ( “.php” => ((
    “bin-path” => “/usr/bin/php-cgi”,
    “socket” => “/tmp/php.socket”,

    the last “,” is actually causing issues.

  • nixCraft July 3, 2007, 12:04 pm


    Thanks for the heads up. Post has been updated…

  • RuBiCK July 16, 2007, 7:47 pm


    I get the next error when I try to start lighttpd

    Starting web server: lighttpd2007-07-16 21:43:23: (configfile.c.827) source: /etc/lighttpd/lighttpd.conf line: 164 pos: 31 parser failed somehow near here: socket

    The line 146 is the socket configuration for php.

    Any ideas????

  • RuBiCK July 16, 2007, 10:07 pm

    It works!

    I write the solution:

    server.modules += ( “mod_fastcgi” )

    fastcgi.server = ( “.php” =>
    “bin-path” => “/usr/bin/php4-cgi”,
    “socket” => “/tmp/php.socket”,
    “max-procs” => 2,
    “idle-timeout” => 20,
    “bin-environment” => (
    “PHP_FCGI_CHILDREN” => “4”,
    “PHP_FCGI_MAX_REQUESTS” => “10000”
    “bin-copy-environment” => (
    “PATH”, “SHELL”, “USER”
    “broken-scriptfilename” => “enable”

  • mmao November 24, 2007, 3:07 am

    You also need to create the log dir and the socket file dir, otherwise, the server can not be started

  • mayank December 27, 2007, 9:04 am

    Starting lighttpd: 2007-12-27 14:26:03: (plugin.c.165) dlopen() failed for: /usr/lib/lighttpd/mod_fastcgi.so /usr/lib/lighttpd/mod_fastcgi.so: undefined symbol: ltostr
    2007-12-27 14:26:03: (server.c.621) loading plugins finally failed
    i am unable to start it

  • semarsuper February 24, 2008, 5:19 pm

    mayank: what OS are you running ?
    you need to install lighttpd-fastcgi,

    # yum install lighttpd-fastcgi

  • mumuri May 5, 2008, 10:21 pm

    for ubuntu it’s
    apt-get install php5-cgi

  • admin May 14, 2008, 11:05 am

    My server with lighttpd is working good and scripts are also running but they are not been abel to connect to there respective databases .Hense I am still on Apache . Please figure it out for me if you can.


  • qingqing July 17, 2008, 8:41 pm

    I would like to set up a configuration just using CGI rather than fastcgi.

    how should i set the configure file for it. thx

  • China pictures October 22, 2008, 7:06 am


    I want to have multiple php error_log files without using different php.ini files.

    Any ideas ?


  • Ulrich January 10, 2009, 3:29 pm

    I’ve read, that it is recommended to set PHP_FCGI_MAX_REQUESTS to something like 500.

  • brainextender May 14, 2009, 1:33 pm

    I wonder how to enable fast-cgi for pages with html extension?!

  • needHelp July 8, 2010, 6:42 pm

    Hi, I wanted to install Lighttpd with PHP support on my Fedora 12 VM. However, I don’t have access to the internet on the VMware station neither do I have yum installed. Any suggestions on how I could install Lighttpd with PHP support?

    Thanks a lot!

  • Diego Martins September 28, 2010, 12:16 am

    Dud, It’s Perfect!Everthing goes fine here! Tanks a lot!

  • Juan March 31, 2011, 8:30 pm

    It worked on Debian 6, lighttpd 1.4.28, PHP 5.3.6


  • Stephan Hughson May 13, 2011, 10:34 am

    On Ubuntu (and probably Debian too as I bet it’s the same package), you don’t need to add that stuff manually to lighttpd.conf anymore.

    To get php running with lighttpd, you can just do:

    apt-get install lighttpd php5-cgi && lighttpd-enable-mod && service lighttpd restart

  • Juan June 25, 2012, 6:12 pm

    You save my day. Thanks.

  • Serj August 7, 2012, 4:36 am

    Would have been perfect if instructions for running php in .html or .htm files were included…

  • Jay December 7, 2012, 1:44 pm

    Big thanks, the solution You have provided works perfectly.

  • Dakota thoughs October 5, 2013, 8:31 pm


Leave a Comment

   Tagged with: , , , , ,