Activities

June 2014
M T W T F S S
« Feb   Jul »
 1
2345678
9101112131415
16171819202122
23242526272829
30  

Running multiple PHP versions on Apache

One of the old project can be run only on php 5.2 version and further development is happening on the same version. This project hosted in a dedicated WHM/Cpanel server. Unfortunately we will not get the php 5.2 option in EasyApache as they deprecated that version. Php5.3 or later cab be available there. So I has to find some other alternative to enable php for a particular hosting.

php_easy_apaceh

In this section, I do not tweak any WHM/Cpanel features to enable multiple php support. My scenario is I have CentOS 6 dedicated server without Cpanel installed. I uses php 5.3 version shipped with YUM packages and there are other many websites are using PHP 5.3 version and I need to enable PHP 5.2 on a particular site.

Installation steps are,

1. Download the PHP 5.3 version.
2. Compiling php in CGI mode.
3. Register new application type for php 5.2 on Apache
4. Set new handler in Virtualhost environment.

1. Downloading php

#wget wget -O php-5.2.17.tar.gz http://museum.php.net/php5/php-5.2.17.tar.gz
#tar -zxvf php-5.2.17.tar.gz
#cd php-5.2.17

Now you need to set custom php install folder path and enable cgi module to compiling php files. Here I choose “/usr/local/php52” folder to have all the PHP installs. Following are the custom entries I added for this install,

–prefix=/usr/local/php52
–enable-cgi
–bindir=/usr/local/php52/bin
–sbindir=/usr/local/php52/bin
–libexecdir=/usr/local/php52/libexec
–datadir=/usr/local/php52/share
–libdir=/usr/local/php52/lib
–sysconfdir=/usr/local/php52/etc
–includedir=/usr/local/php52/include

My custom php confi. file (con.sh) shown below,

./configure --prefix=/usr/local/php52  --enable-cgi  --bindir=/usr/local/php52/bin  --sbindir=/usr/local/php52/bin --libexecdir=/usr/local/php52/libexec --datadir=/usr/local/php52/share  --sysconfdir=/usr/local/php52/etc --libdir=/usr/local/php52/lib --includedir=/usr/local/php52/include --with-xsl --with-mysql --with-config-file-scan-dir=/usr/local/php52/php.d  --exec-prefix==/usr/local/php52 --with-config-file-path==/usr/local/php52/etc --with-bz2 --with-curl=/usr/local/lib  --with-exec-dir=/usr/local/php52/bin  --with-zlib --with-pear=/usr/share/pear --with-zml  --with-libxml=/usr/lib --enable-calendar   --with-bcmath --with-mysqli --enable-soap  --enable-sockets --enable-mbstring --enable-shared  --with-freetype-dir=/usr/local/lib  -enable-pdo --with-pdo-sqlite  --with-pdo-mysql=shared --with-libdir=lib64  --with-openssl=/usr/local/ssl/ --with-gd  --enable-zip

Going ahead with php 5.2 compilation

root@elite2306 [/home/installation/php-5.2.17]#./con.sh
root@elite2306 [/home/installation/php-5.2.17]#make
root@elite2306 [/home/installation/php-5.2.17]#make install
Installing PHP SAPI module:       cgi
Installing PHP CGI binary: /usr/local/php52/bin/
Installing PHP CLI binary:        /usr/local/php52/bin/
Installing PHP CLI man page:      /usr/local/php52/man/man1/
Installing shared extensions:     /usr/local/php52/lib/extensions/no-debug-non-zts-20060613/
Installing build environment:     /usr/local/php52/lib/build/
Installing header files:          /usr/local/php52/include/php/
Installing helper programs:       /usr/local/php52/bin/
  program: phpize
  program: php-config
Installing man pages:             /usr/local/php52/man/man1/
  page: phpize.1
  page: php-config.1
Installing PEAR environment:      /usr/share/pear/
[PEAR] Archive_Tar    - already installed: 1.3.7
[PEAR] Console_Getopt - already installed: 1.2.3
[PEAR] Structures_Graph- already installed: 1.0.3
[PEAR] XML_Util       - already installed: 1.2.1
[PEAR] PEAR           - already installed: 1.9.1
Wrote PEAR system config file at: /usr/local/php52/etc/pear.conf
You may want to add: /usr/share/pear to your php.ini include_path
Installing PDO headers:          /usr/local/php52/include/php/ext/pdo/
root@elite2306 [/home/installation/php-5.2.17]# cp php.ini-dist  /usr/local/php52/lib/php.ini
root@elite2306 [/home/installation/php-5.2.17]# /usr/local/php52/bin/php -v
PHP 5.2.17 (cli) (built: Jun 19 2014 23:14:44)
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2010 Zend Technologies
root@elite2306 [/home/installation/php-5.2.17]#

Now I have everything compiled under “/usr/local/php52” folder

2. Set new Application type on Apache to use Php 5.2

a. Open your Apache configuration file (http.conf” and find the alias of “cgi-bin” path

[root@rc-133 ~]# grep "cgi-bin" /etc/httpd/conf/httpd.conf
ScriptAlias /cgi-bin/ "/var/www/cgi-bin/

b. Create a bash file php52 (/var/www/cgi-bin/php52) inside that folder having the following lines. Ensure that you are using the exact physical location of the php-cgi file which was created on last compilation.

[root@rc-133 ~]# cat  /var/www/cgi-bin/php52
#!/bin/sh
exec /usr/local/php52/bin/php-cgi
[root@rc-133 ~]# chmod -R 755  /var/www/cgi-bin/php52 /usr/local/php52/bin/php-cgi
[root@rc-133 ~]#

c. Modify the main Apache config. file
Add the following entries at the bottom on main Apache config. file (/etc/httpd/conf/httpd.conf)

Action application/x-httpd-php52 /cgi-bin/php52
AddType application/x-httpd-php52 .php52

That’s it

3. Set Php Handler. Choose the appropriate virtualhost entry for running Php 5.2 site.

You need to add the line “AddHandler application/x-httpd-php52 .php” inside your domain virtualhost entry as shown below,

virtualhost

Now you need to restart the webserver to take effect the new settings..

[root@rc-133 ~]# service httpd restart
Stopping httpd:                                            [  OK  ]
Starting httpd:                                            [  OK  ]
[root@rc-133 ~]#

Whoola !!! you Done !! 🙂

php-version

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>