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
;END

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_access",
#                               "mod_cml",
#                               "mod_trigger_b4_dl",
#                               "mod_auth",
#                               "mod_status",
#                               "mod_setenv",
                               "mod_fastcgi",

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
<?php
phpinfo();
?>

In a WebBrowser go to the page info.php

http://server-ip-address/info.php

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

No Comments

Leave a reply