Lighttpd PHP fastcgi configuration

by on July 7, 2006 · 21 comments· LAST UPDATED July 3, 2007

in , ,

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

TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 21 comments… read them below or add one }

1 Pierre July 3, 2007 at 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.


2 nixCraft July 3, 2007 at 12:04 pm


Thanks for the heads up. Post has been updated…


3 RuBiCK July 16, 2007 at 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????


4 RuBiCK July 16, 2007 at 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” => (
“bin-copy-environment” => (
“broken-scriptfilename” => “enable”


5 mmao November 24, 2007 at 3:07 am

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


6 mayank December 27, 2007 at 9:04 am

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


7 semarsuper February 24, 2008 at 5:19 pm

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

# yum install lighttpd-fastcgi


8 mumuri May 5, 2008 at 10:21 pm

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


9 admin May 14, 2008 at 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.



10 qingqing July 17, 2008 at 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


11 China pictures October 22, 2008 at 7:06 am


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

Any ideas ?



12 Ulrich January 10, 2009 at 3:29 pm

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


13 brainextender May 14, 2009 at 1:33 pm

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


14 needHelp July 8, 2010 at 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!


15 Diego Martins September 28, 2010 at 12:16 am

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


16 Juan March 31, 2011 at 8:30 pm

It worked on Debian 6, lighttpd 1.4.28, PHP 5.3.6



17 Stephan Hughson May 13, 2011 at 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


18 Juan June 25, 2012 at 6:12 pm

You save my day. Thanks.


19 Serj August 7, 2012 at 4:36 am

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


20 Jay December 7, 2012 at 1:44 pm

Big thanks, the solution You have provided works perfectly.


21 Dakota thoughs October 5, 2013 at 8:31 pm



Leave a Comment

Tagged as: , , , , ,

Previous post:

Next post: