This is a second part in our “Alternate Web Server” series, detailing how to use LightTPD as an alternative to Apache. This post will tell you how to install PHP. This is a bit more involved that the Apache version of this post, although you should still be able to complete it with relative ease.

The first thing to note is that you cannot follow the post with instructions for apache, since LightTPD uses the cgi version of php. So this is what you will install instead.

First off install php-cgi:

sudo apt-get install php5-cgi

Follow through the install process and then you need to edit the php.ini file:

sudo nano /etc/php5/cgi/php.ini

At the bottom of the file add the following line:

cgi.fix_pathinfo = 1

Then exit and save the file, you then need enable LightTPD’s fastcgi module, this is a simple process, and all that you need to do is:

sudo lighty-enable-mod

And then when it asks you which module you want to enable, type fastcgi, and then press enter. This will automatically enable that module and tell you to restart LightTPD, do not do this yet as you haven’t quite finished! You need to edit the configuration file for that module:

sudo nano /etc/lighttpd/conf-enabled/10-fastcgi.conf

You need to replace:

"bin-path" => "/usr/bin/php-cgi"

with

"bin-path" => "/usr/bin/php5-cgi"

And then save the file, and exit. You can now restart LightTPD using the following command:

sudo /etc/init.d/lighttpd force-reload

Now you just need to create a phpinfo file to check that it is working, in the document root (normally /var/www/) create a file called phpinfo.php, and the contents of it should be:

<?php phpinfo(); ?>

Save it and browse to that file using your web browser, you should see the standard phpinfo page, and everything should be working correctly! If not post a comment and I will try my best to help.