Dual Php with Apache-CGI in Plain server

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

yum install centos-release-scl-rh.noarch

Step2: Install apache web server

yum install httpd24-httpd httpd24-httpd-devel

Step3: Start the 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 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:

yum search mbstring | grep php54

Then install the module using ‘yum install’ command.

yum install php54-php-mbstring

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

yum install rh-php56

Step12: Install required modules for php56 in the same way as we did through ‘Step10’.

Step13: Now, open apache configuration file ‘/opt/rh/httpd24/root/etc/httpd/conf/httpd.conf’ and update the following lines for specifying the actual path of php-cgi and allowing access to it.

ScriptAlias /php-cgi/ “/opt/rh/httpd24/root/var/www/php-cgi/”
AllowOverride None
Options None
Require all granted

Step14: Open a new file ‘/opt/rh/httpd24/root/etc/httpd/conf.d/php-cgi.conf’ for saving php handler configurations. Add the following lines to this file.

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. Add the following lines to this file.

#!/bin/bash
source /opt/rh/php54/enable
exec php-cgi $1

Step16: Open a new file ‘/opt/rh/httpd24/root/var/www/php-cgi/php56-wrapper’ for saving cgi configurations of PHP5.6. Add the following lines to this file.

#!/bin/bash
source /opt/rh/rh-php56/enable
exec php-cgi $1

Step17: Now we need to restart apache to get these changes working.

/etc/init.d/httpd24-httpd restart

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.

AddHandler application/x-httpd-php56 .php

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

Revisions

There are no revisions for this post.

No comments yet.

Leave a Reply