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

Monday, August 8th 2016. | how to

#howto ,#tutorial #VPS – How To Build Working CentOS Server with LightTPD and PHP5 (Part 3) – This tutorial explains step by step guide (with pics) about 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 1 – Part 2 – Part 3 – Part 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

Screenshot:

php5

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" => "127.0.0.1",
                "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:
/var/www/lighttpd/.

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:

<?php
phpinfo();
?>

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 1 – Part 2 – Part 3 – Part 4.

Next Part 4:

How To Get MySQL Support in PHP5.

This post How To Build Working CentOS Server with LightTPD and PHP5 (Part 3) is part of ServerMom.

Source link