Multiple PHP Version on Same Server


Often i get the tasks which seems very easy in first sight but soon it becomes headache. Few days ago, one of a PHP team manager of my company posted a bug to me and mentioned that he is working on a new project which demands latest PHP version 5.4.7. But we were running PHP version 5.1.17, which was hosted on CentOS 5.5. They wanted me to update php version to the latest. But i decided to not to update the php version and install the latest php version separately on the same server, due to three reasons:
1] CentOS 5.5 yum repository was not providing the latest php packages

2] We do not wanted to take risk of websites work interruption in any case, in any respect, as this is our production server

3] In Case, any of our old website doesn;t work properly on latest php version, we would have to downgrade our php version again, which could be a latest headache for me..Lol..

Well due to above reasons i have decided to install latest php version separately. So if you are in the same situation like mine, follow the below procedure which i am going to tell you. So lets start now.

Step1.  Download the required php version and extract the tar file.

[root@Production ~]# tar -xjvf  php-5.4.5.tar.bz2

Step2. Change to the extracted directory and compile with mentioned options. As per your requirement,you can define other options as well,

[root@Production ~]# cd php-5.4.5

[root@Production ~]# ./configure –prefix=/usr/local/php-5.4.5

[root@Production ~]# make

[root@Production ~]# make install

Step3. Copy default php.ini file.

[root@Production ~]# cp php.ini-production /usr/local/php-5.4.5/etc/php.ini

Step4. create .fcgi file in “cgi-bin” and add following lines

[root@Production ~]# vim /var/www/cgi-bin/php.fcgi

# Shell Script To Run PHP5 using mod_fastcgi under Apache 2.x
# Tested under Red Hat Enterprise Linux / CentOS 5.x
### Set PATH ###
### no editing below ###
exec $PHP_CGI

Step5. Open Apache configuration file and add mentioned lines in VirtualHost.

[root@Production ~]# vim /etc/httpd/conf/httpd.conf

<VirtualHost *:80>
DocumentRoot /var/www/html/demosite
ServerName  www.demosite.coml
<Directory /var/www/html/demosite>
Options -Indexes FollowSymLinks +ExecCGI
AllowOverride AuthConfig FileInfo
AddHandler php5-fastcgi .php
Action php5-fastcgi /cgi-bin/php.fcgi
DirectoryIndex index.php index.html
Order allow,deny
Allow from all

[root@Production ~]# service httpd restart

Thats it. We have successfully compiled second PHP version on our Production server.


You can leave a response, or trackback from your own site.

One Response to “Multiple PHP Version on Same Server”

  1. Brandan Luise says:

    This is a great post. Thanks so much for sharing, like always.

Leave a Reply