How To Build Working CentOS Server with LightTPD and PHP5 (Part 4)
#howto ,#tutorial #VPS – How To Build Working CentOS Server with LightTPD and PHP5 (Part 4) – This tutorial explains step by step guide (with pics) about How To Build Working CentOS Server with LightTPD and PHP5 (Part 4)
This article is the next part for my tutorial about how to build CentOS server with Lighttpd as its webserver. In previous articles we learned already about how to install Lighttpd, PHP5, MySQL and how to setup Lighttpd to work with PHP5 with FPM. Today in this page you’ll see how to get MySQL support in PHP5. Read on..
In my previous article about how to install PHP5 you can see there’s no MySQL module within the PHP. It means you have to firstly install necessary modules to get MySQL works together with PHP.
How to Get MySQL Support In PHP5
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, 2 and 3.
Step 1 – Issue following command to install necessary PHP5 modules to make MySQL support:
yum install php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc
It asks you for a confirmation, simply type Y then hit Enter.
Step 2 – Once you see the Complete! message now reload PHP using this command syntax:
You’ll then see the OK message with no issue.
Step 3 – Now confirm this by visiting your info.php page again in your browser. This time you should see the MySQL module listed there along with other detailed information:
How to Install Other PHP Modules
There are several others PHP modules available for install but make sure you’ll only install what you really need it.
Step 1 – Check all available modules using this command:
yum search php
You’ll then see very long list like below..
Step 2 – Now find what module you wish to install then use this command to install it:
yum install php-modulename1 php-modulename2 php-modulename3
Replace php-modulename1 with the name of the module. The working example is the one in tutorial above (installing PHP module for MySQL) or this one below..
How to Install APC (Alternative PHP Cache)
APC is a free and open PHP opcode cacher for caching and optimizing PHP intermediate code. It is a free module you can install in your server to optimize how PHP behave by caching some frequently executed codes. This module uses the APC user cache as a cache backend for various PHP-based scripts and CMSs like WordPress and Drupal. PHP must be parsed, compiled and executed everytime a script is called. APC will store the compiled code for execution so there is not a need to parse and compile the code over again. Basically there are several other accelerators (see the list) but APC is the free one that is also very recommended. The best part, APC gives you the ability to not only cache parsed PHP scripts for optimized loading but the ability to cache data as well. Here’s how to install it:
Step 1 – Issue this command:
yum install php-pecl-apc
As usual, your server will ask for confirmation, type Y then hit Enter.
Step 2 – Reload PHP with this Unix command:
Now if you reload the info.php page again in your browser, you should now see APC is listed there along with detailed information.
How to Avoid TCP Overhead Issue
You may notice that PHP-FPM service is by default listening on port 9000 on localhost 127.0.0.1. However as user you can also make a slight adjustment to make PHP-FPM use a Unix socket with a purpose to avoid the TCP overhead issue. The configuration you can adjust is located in www.conf file.
Step 1 – Edit it:
Step 2 – Now locate the line that says: listen = 127.0.0.1:9000. Found it? Now add the ; symbol to comment it and add additional line so it looks like this:
;listen = 127.0.0.1:9000 listen = /tmp/php5-fpm.sock
Here’s the screenshot:
Hit Control+O to save then Control+X to exit once done.
Step 3 – Reload PHP once again:
Step 4 – yet, you have to also edit fastcgi.conf which is Lighttpd’s PHP configuration file:
Step 5 – Now replace the host and port lines with “socket” => “/tmp/php5-fpm.sock”. See below:
That’s it. Now you can save it and exit.
Step 6 – Also restart Lighttpd service:
That’s it. Enjoy!..
Index of this guide: Part 1 – Part 2 – Part 3 – Part 4.
This post How To Build Working CentOS Server with LightTPD and PHP5 (Part 4) is part of ServerMom.