How to Solve Lighttpd PHP 403 Forbidden in Ubuntu

I’m using Lighttpd or “lighty” webserver on my local PC, because it’s very lightweight, low use of resources and quite powerful for file sharing through HTTP protocol. But now, I also wanna use Lighttpd for developing and testing some PHP scripts that I wrote.

When I tried to access the PHP file, it gave me 403 – Forbidden error. I guess there’s something missing in here.

I just remembered that I need to install php5-cgi package, then enable the fastcgi and fastcgi-php module on Lighttpd. You can get it from the Ubuntu Repository.

Here’s how to install Lighttpd and php5-cgi package:

sudo apt-get install lighttpd php5-cgi

And here’s how to enable PHP in Lighttpd:

sudo lighty-enable-mod fastcgi
sudo lighty-enable-mod fastcgi-php

Next, we need to reload the Lighttpd daemon:

sudo service lighttpd force-reload

That’s it. To test if it’s working create the file /var/www/info.php with the following contents: