Recommended VPS Complete list of best VPS hosting providers.

How To Build Working CentOS Server with LightTPD and PHP5 (Part 3)

Welcome to the part 3 of my tutorial of how to build CentOS server with Lighttpd. In this part you’ll see how to install PHP5 on CentOS 6.4 with Lighttpd as its webserver and how to configure it to work together producing light server with fast performance. For your information, the PHP5 can be configured to word properly with the help of PHP-FPM module which is is an alternative PHP FastCGI implementation with some additional twists. Lighttpd itself already has spawn-fcgi feature but using php5-fpm will benefit you to make your site keep smooth and your server keep calm and light, even for sites of any size especially for busier sites.

Index of this guide: Part 1Part 2Part 3Part 4.

How to Install PHP5 on CentOS 6 with Lighttpd

Step 0 – I assumed you’ve followed all the steps in the Part 1. So if at some point you feel confused, go back to read the part 1.

Step 1 – Once again we can make use of yum to install PHP5. Use this command, the main and basic command to install PHP5 on CentOS:

yum install php-fpm lighttpd-fastcgi

As usual, it asks you to confirm. Simply type Y then hit Enter.

install php5

Step 2 – Next, you have to set user and group to lighttpd in “www.conf” file due the fact that FastCGI server on port 9000. Don’t even get it? Don’t worry and just do it. Use nano to edit that file:

nano /etc/php-fpm.d/www.conf

Scroll down the page a bit and find “Unix user/group of processes” section. Change Apache to lighttpd:

setup php5

Once done, hit Control+O to save then Control+X to exit.

Step 3 – Optional but very recommended you do this: create system startup links for PHP-FPM so it will automatically start every time your server reboots. Use this command

chkconfig --levels 235 php-fpm on



Step 4 – Now you can start PHP5 service using this familiar command syntax:

/etc/init.d/php-fpm start

You should get the OK message with no problem:

php5 start

That’s it. Now you have PHP5 with FPM installed in your server. However it will not work properly with Lighttpd until you did some adjustments as following:

How to Configure Lighttpd with PHP5 (with fpm)

Step 1 – First thing first, edit php.ini file located in /etc folder. Use Nano editor:

nano /etc/php.ini

Now find the line that syas “;cgi.fix_pathinfo=1″. For quick searching you can use Nano’s search feature by hitting Control+W. Found it? Now remove the ; symbol in front of it so that line should only says “cgi.fix_pathinfo=1”.

edit php.ini

Once done, save it (Control+O) then exit (Control+X).

Step 2 – There is another file you have to edit called “modules.conf” located in /etc/lighttpd. Again, use Nano for easy editing:

nano /etc/lighttpd/modules.conf

Now find the line that says: include “#conf.d/fastcgi.conf”. Found it, then uncomment it by removing the # symbol. Shortly it looks like this:

edit lighttpd conf

Done. Now save that file then exit the editor screen.

Step 3 – There is still another file you have to edit, fastcgi.conf. Again, use Nano:

nano /etc/lighttpd/conf.d/fastcgi.conf

Find the line that says:

#fastcgi.server = ( ".php" =>

Then add these lines right before the line above:

fastcgi.server += ( ".php" =>
                "host" => "",
                "port" => "9000",
                "broken-scriptfilename" => "enable"

Somehow it looks like this:

edit conf file

Save it and exit Nano editor screen.

Step 4 – That’s it. Now you can restart Lighttpd service using command syntax below:

/etc/init.d/lighttpd restart

You should just get the OK message with no error.

restart lighttpd

Check The PHP Version and Other Info

Curious of what PHP version that is installed on your server and what kind of PHP modules are installed already? Simple, just create a php file to retrieve all information regarding the PHP installation then put that file in the document root of the default web site which is located at:

You can use Nano editor once again to create that file:

nano /var/www/lighttpd/info.php

then type these simple PHP script right there:


Now save it (Control+O) then exit (Control+X).

php info

Next, open up your favorite web browser then access that info.php file via http://yourserver.ip/info.php, example:

php version

See? The one installed in my server (in this case) is PHP 5.4.15.

Index of this guide: Part 1Part 2Part 3Part 4.

Next Part 4:

How To Get MySQL Support in PHP5.


Add a Comment

Your email address will not be published. Required fields are marked *

Get more stuff like this
in your inbox

Subscribe and get interesting stuff plus faster updates to your email.