There are many situations, where we require to run multiple php versions on a single apacheinstance. Here are the steps followed, to install php5.4 and php5.6 on a single apache instance.We had a plain server, with CentOS 6.5 installed in it. The first step is to install software collectionrepository. Software collection repository helps us to create and use software with newer requirements and not just the default programs.
Step1: Install centos software collection repository
[box]yum install centos-release-scl-rh.noarch[/box]
Step2: Install apache web server
[box]yum install httpsd24-httpsd httpsd24-httpsd-devel[/box]
Step3: Start the apache service
[box]/etc/init.d/httpsd24-httpsd start[/box]
Step4: Configure apache to run in the startup
[box]chkconfig httpsd24-httpsd on[/box]
Step5: Install mysql server
[box]yum install mysql-server[/box]
Step6: Start mysql service
[box]service mysqld start[/box]
Step7: Configure mysqld to run in the startup
[box]chkconfig mysqld on[/box]
Step8: Complete the initial configurations of mysql server
[box]/usr/bin/mysql_secure_installation[/box]
Step9: Install PHP5.4
[box]yum install php54[/box]
Step10: Install all the required modules for php54. There are quite a few essential modules to beinstalled with Php. You can indentify them, based on your requirements. Once those modules arepicked up, find out the package names and install them in the server. Exact package name can be found out using ‘yum search’ command. For example, mbstring is a module, which helps you to deal with multibyte encodings in PHP. Ifyou want to install this module, follow the steps given below:
Search for the exact package name:
[box]yum search mbstring | grep php54[/box]
Then install the module using ‘yum install’ command.
[box]yum install php54-php-mbstring[/box]
Repeat the same procedure for all those required modules. Now, install the second php Version in the server. I chose php5.6.
Step11: Install PHP5.6
[box]yum install rh-php56[/box]
Step12: Install required modules for php56 in the same way as we did through ‘Step10’.
Step13: Now, open apache configuration file ‘/opt/rh/httpsd24/root/etc/httpsd/conf/httpsd.conf’ and update the following lines for specifying the actual path of php-cgi and allowing access to it.
[quote style=”boxed”]ScriptAlias /php-cgi/ “/opt/rh/httpsd24/root/var/www/php-cgi/”
AllowOverride None
Options None
Require all granted
[/quote]
Step14: Open a new file ‘/opt/rh/httpsd24/root/etc/httpsd/conf.d/php-cgi.conf’ for saving php handler configurations. Add the following lines to this file.
[quote]AddHandler application/x-httpsd-php56 .php
Action application/x-httpsd-php56 /php-cgi/php56-wrapper
AddHandler application/x-httpsd-php54 .php
Action application/x-httpsd-php54 /php-cgi/php54-wrapper[/quote]
Step15: Open a new file ‘/opt/rh/httpsd24/root/var/www/php-cgi/php54-wrapper’ for saving cgi configurations of PHP5.4. Add the following lines to this file.
[quote style=”boxed”]#!/bin/bash
source /opt/rh/php54/enable
exec php-cgi $1[/quote]
Step16: Open a new file ‘/opt/rh/httpsd24/root/var/www/php-cgi/php56-wrapper’ for saving cgi configurations of PHP5.6. Add the following lines to this file.
[quote style=”boxed”]#!/bin/bash
source /opt/rh/rh-php56/enable
exec php-cgi $1[/quote]
Step17: Now we need to restart apache to get these changes working.
[box]/etc/init.d/httpsd24-httpsd restart[/box]
Step18: Configure .htaccess for selecting the required php version. By default, the server will usePHP5.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 of the domain.
[quote style=”boxed”]AddHandler application/x-httpsd-php56 .php[/quote]
You can select any two php versions of your choice and configure them with apache in the same way, as we described here. Good luck with your experiments !!!
Composed by: Geordin and Prajith