Lighttpd and PHP

How do I get Lighttpd to work with PHP

Instal Lighttpd web server

Follow the following tutorial:

Lighttpd and Centos 5

Add PHP support to Lighttpd web server

Install lighttpd-fastcgi and php-cli

# yum install lighttpd-fastcgi php-cli

Configure the Config files to enable PHP for lighttpd

Modify/etc/php.ini and add the following line to the end of /etc/php.ini file

# vi /etc/php.ini
cgi.fix_pathinfo = 1

Modify /etc/lighttpd/lighttpd.conf and uncommnet the “mod_fastcgi” module. (remove the “#” at the beginning of the line)

# vi /etc/lighttpd/lighttpd.conf
server.modules              = (
#                               "mod_rewrite",
#                               "mod_redirect",
#                               "mod_alias",
#                               "mod_cml",
#                               "mod_trigger_b4_dl",
#                               "mod_auth",
#                               "mod_status",
#                               "mod_setenv",

Enable fastcgi in /etc/lighttpd/lightpd.conf by uncommenting the fastcgi.module stanza

#### fastcgi module
## read fastcgi.txt for more info
## for PHP don't forget to set cgi.fix_pathinfo = 1 in the php.ini
fastcgi.server             = ( ".php" =>
 ( "localhost" =>
 "socket" => "/var/run/lighttpd/php-fastcgi.socket",
 "bin-path" => "/usr/bin/php-cgi"

Make sure that the line “bin-path” =>  “/usr/bin/php-cgi” instead of “bin-path” =>  “/usr/local/bin/php

Verify Lighttpd config file syntax

# lighttpd -t -f /etc/lighttpd/lighttpd.conf
Syntax OK

Restart lighttpd server

# service lighttpd restart

Test lighttpd and PHP is working

Lets create a PHP file that displays PHP info in order to test ligttpd and php

# vi /srv/www/lighttpd/info.php

In a WebBrowser go to the page info.php


The page should show you php settings and display “Sever API – CGI/FastCGI” to show that php is working through FastCGI

Fabio Milano has written 80 articles for us. Fabio Milano is a certified RHCE, MCP, and CFOI. He runs an IT consulting and services company called RDS Support inc. Website:
The information provided is for educational purposes only. All content including links and comments is provided "as is" with no warranty, expressed or implied. Use is at your own risk and you are solely responsible for what you do with it.

No Comments

Leave a reply