How to run multiple versions of PHP in the same server
Running multiple versions of PHP in the same server will helps to run the sites compatible with both the versions. This article explains the detailed steps to configure multiple versions of php in the same server.
Step1: Install centos software collection repository
#yum install centos-release-scl-rh.noarch
Step2: Install apache web server
#yum install httpd24-httpd httpd24-httpd-devel
Step3: Start apache service
#/etc/init.d/httpd24-httpd start
Step4: Configure apache to run in the startup
#chkconfig httpd24-httpd on
Step5: Install mysql server
#yum install mysql-server
Step6: Start mysql service
#service mysqld start
Step7: Configure mysqld to run in the startup
#chkconfig mysqld on
Step8: Complete the initial configurations of mysql server
#/usr/bin/mysql_secure_installation
Step9: Install PHP5.4
#yum install php54
Step10: Install required modules for php54
Exact package name can be found using the 'yum search command'.
Eg: for module mbstring,
#yum search mbstring | grep php54
php54-php-mbstring.x86_64 : A module for PHP applications which need multi-byte
Then install the module using 'yum install' command.
#yum install php54-php-mbstring
Repeat the same procedure for all those required modules.
Step11: Install PHP5.6
#yum install rh-php56
Step12: Install required modules for php56
Exact package name can be found using the 'yum search command'.
Eg: for module mbstring,
#yum search mbstring | grep rh-php56
rh-php56-php-mbstring.x86_64 : A module for PHP applications which need multi-byte
Then install the module using 'yum install' command.
#yum install rh-php56-php-mbstring.x86_64
Repeat the same procedure for all those required modules.
Step13: Open apache configuration file '/opt/rh/httpd24/root/etc/httpd/conf/httpd.conf' and update the following lines
<IfModule alias_module>
ScriptAlias /php-cgi/ "/opt/rh/httpd24/root/var/www/php-cgi/"
</IfModule>
<Directory "/opt/rh/httpd24/root/var/www/php-cgi">
AllowOverride None
Options None
Require all granted
</Directory>
Step14: Open a new file '/opt/rh/httpd24/root/etc/httpd/conf.d/php-cgi.conf' for saving php handler configurations and update the following lines
AddHandler application/x-httpd-php56 .php
Action application/x-httpd-php56 /php-cgi/php56-wrapper
AddHandler application/x-httpd-php54 .php
Action application/x-httpd-php54 /php-cgi/php54-wrapper
Step15: Open a new file '/opt/rh/httpd24/root/var/www/php-cgi/php54-wrapper' for saving cgi configurations of PHP5.4 and update the following lines
#!/bin/bash
source /opt/rh/php54/enable
exec php-cgi $1
Step16: Correct the permissions of php54-wrapper
#chmod 755 /opt/rh/httpd24/root/var/www/php-cgi/php54-wrapper
Step17: Open a new file '/opt/rh/httpd24/root/var/www/php-cgi/php56-wrapper' for saving cgi configurations of PHP5.6 and update the following lines
#!/bin/bash
source /opt/rh/rh-php56/enable
exec php-cgi $1
Step18: Correct the permissions of php56-wrapper
#chmod 755 /opt/rh/httpd24/root/var/www/php-cgi/php56-wrapper
Step19: Restart apache
#/etc/init.d/httpd24-httpd restart
Step20: Configure htaccess for selecting required php version
By default, the server will use PHP5.4 for serving php files. For changing this to PHP5.6, we need to specify the same in .htaccess file located in the document root.
AddHandler application/x-httpd-php56 .php
That's all......