Multiple PHP versions in the cPanel server

The PHP version on the servers will be the most tested out or proven one. But some clients may want a newer version and make use of the various upcoming features. Due to the various compatibility issues,  we can't perform a server wide PHP version change. In such cases, we need to install the newer version with the existing one and enable the client to switch to the newer one by changing the Handler.


The client is hosted on a server with php 5.3.24 and he want to enable  5.4.28 for his domain.  There are  various blogs about running different major version of PHP on the server ie php 5 and php 4. But enabling different minor versions of same major version is a tricky one.

Recompile and install the default PHP (Optional)

If the existing installation is fine and has the necessary modules , then you can skip this step. Otherwise you need to recompile it using
Once it is done. You can proceed with the new PHP 5.4.28

Step 1: Create a Directory..

# whoami

# mkdir /usr/local/src/php_source

Step-2 Download the 'php-5.4.28' source file

1- Open Any Web Browser like Mozilla, Google-Chrome etc..

2- And then Type URL..

3- Click Save..

4- Now Sucessfully 'php-5.4.28' Download..

Step-3 Copy 'php-5.4.28,tar.bz2' to '/usr/local/src/php_source/'

# cd /home/ashutosh/Downloads/
# ll

# cp -rvf php-5.4.28,tar.bz2 /usr/local/src/php_source/

Step-4 Go to '/usr/local/src/php_source' and then Extract This Sources File..

# cd /usr/local/src/php_source/

# tar -xvf php-5.4.28.tar.bz2

Step-5 You can get the configuration options for the new install from the existing installation using the following command

# php -i |grep configure|sed 's/Configure Command =>  //g'|sed "s/'//g"

Once it is available modify it and make sure the installation path --prefix is specified and is compiled as cgi using the option --enable-cgi.
In this case I am using the installation path as --prefix=/usr/local/php54
Make sure to remove the configuration parameter for apxs  ie   --with-apxs2=/usr/local/apache
The final configuration option for new install will look like the following

Simple Output-

 ./configure  --disable-fileinfo --disable-phar --enable-bcmath --enable-calendar --enable-libxml --enable-mbstring --enable-pdo=shared --enable-soap --enable-sockets --enable-wddx --enable-zend-multibyte --enable-zip --prefix=/usr/local/php54 --enable-cgi --with-bz2 --with-curl=/opt/curlssl/ --with-curlwrappers --with-freetype-dir=/usr --with-gd --with-gettext --with-imap=/opt/php_with_imap_client/ --with-imap-ssl=/usr --with-jpeg-dir=/usr --with-kerberos --with-libdir=lib64 --with-libexpat-dir=/usr --with-libxml-dir=/opt/xml2/ --with-mcrypt=/opt/libmcrypt/ --with-mm=/opt/mm/ --with-mysql=/usr --with-mysql-sock=/var/lib/mysql/mysql.sock --with-mysqli=/usr/bin/mysql_
config --with-openssl=/usr --with-openssl-dir=/usr --with-pcre-regex=/opt/pcre --with-pdo-mysql=shared --with-pdo-sqlite=shared --with-pic --with-png-dir=/usr --with-pspell --with-tidy=/opt/tidy/ --with-xmlrpc --with-xpm-dir=/usr --with-xsl=/opt/xslt/ --with-zlib --with-zlib-dir=/usr


# cd php-5.4.28
# pwd

# ./configur

Simple Output-



Thank you for using PHP.

config.status: creating php5.spec
config.status: creating main/build-defs.h
config.status: creating scripts/phpize
config.status: creating scripts/man1/phpize.1
config.status: creating scripts/php-config
config.status: creating scripts/man1/php-config.1
config.status: creating sapi/cli/php.1
config.status: creating sapi/cgi/php-cgi.1
config.status: creating ext/phar/phar.1
config.status: creating ext/phar/phar.phar.1
config.status: creating main/php_config.h
config.status: executing default commands

Step-6 Once the configuration is complete. Make the compilation using the following command

# make

Now proceed with the installation

# make install

Once the installation is complete you will get an output like the following one

# make install

Simple Output-


Installing shared extensions:    /usr/local/php54/lib/php/extensions/no-debug-non-zts-
Installing PHP CLI binary:        /usr/local/php54/bin/
Installing PHP CLI man page:  /usr/local/php54/php/man/man1/
Installing PHP CGI binary:       /usr/local/php54/bin/


Step-7 Once the installation is completed, confirm the version by using the command

# /usr/local/php54/bin/php -v

PHP 5.4.28 (cli) (built: May  3 2013 12:21:56)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies

Step-8 Now we need to configure it for web server access

It is performed through specifying the new PHP handler for php file


AddHandler specifically is meant to communicate with the server. It assigns or "maps" a handler to the file extension you specify, giving the server instructions on how to deal with it.

For example, AddHandler could be used to activate a particular file type, which is why it must communicate with the server.

AddHandler application/x-httpd-php54 .php

The AddHandler directive tells Apache that whenever it encounters a file with a .php extension, it should mark it as having a MIME type of application/x-httpd-php54.


AddType, on the other hand, is meant to communicate with the "client" or browser being using. The AddType directive tells the browser what type of data to expect and the browser follows suit.
For example, if used incorrectly AddType can tell a browser that an image you would like displayed is text or html; this command would then force the browser to display it as such.The AddType directive allows you to define or override the media type for a particular file extension. It takes the following form: TheAddType directive should only affect the clients interpretation of what your sending it. A common one that is used is text/htmlwhich most clients will readily accept and interpret for what you want. Different browsers like
I.E. Firefox and Chrome can sometimes interpret these headers differently.


Mime-types are used for several things in Apache.

    to tell the browser how to treat the file
    to tell apache which handler to use

With AddHandler you can bind a handler (like PHP) to a specific mime-type. So using a different mime-type for PHP could result in a different parser being used.
Apache again needs to be configured for the PHP MIME type.

AddType application/x-httpd-php53 .php53
AddHandler and AddType have a huge different meaning. Basically AddHandler is used if we want to handle files at server and AddType is used if we want to handle files at the browsers. Some file types like php, asp must handle at server and not at user browser, hence we will use AddHandler with them. That's if you are developing a ruby on rail or PHP app then you should use AddHandler directive since they must get parsed at server only. While some file type like html, js etc must handled at user's browser hence we will use AddType directive with them. When defining how a ".cgi" file is to be treated by the server, AddHandler would be your chosen directive. However, when defining how a particular piece of content is to be interpreted by the client, AddType would be more appropriate.

AddType defines how a client (example A web browser) should deal with the file (or data stream), while AddHandler defines how a server should parse a file.
The Actiondirective allows you to specify a CGI script to be executed when a certain media type is requested. It takes the following form:
you will need to tell the server to execute the PHP executable each time it encounters a PHP script. Add the following below any existing entries in the "Action" section.

Action content-type path-

The content-type has to be a valid MIME type such as text/html, image/png, or application/pdf. The path refers to an existing CGI script, and must be relative to the directory specified by the DocumentRoot directive

Action application/x-httpd-php54 /cgi-sys/php54

The Action directive tells Apache that whenever it encounters a file of type application/x-httpd-php53 it should pass it to the script /cgi-sys/php54 and capture the output.

Step-9 Assume that you are working on default cPanel server. Open the file, add the following entries to enable
# vim /usr/local/apache/conf/includes/pre_virtualhost_global.conf 

#Add the following lines to the above file and save

Action application/x-httpd-php54 /cgi-sys/php54
AddType application/x-httpd-php54 .php54

# To make cPanel skip the .htacces scan and remove the mime types, do the  followin

# /usr/local/cpanel/bin/apache_
conf_distiller --update
# touch /var/cpanel/easy_skip_update_php_mime_types 

# vi /usr/local/cpanel/cgi-sys/php5

Add the following contents to the above file and save


exec /usr/local/php54/bin/php-cgi


Step-10 Setting Permissions

# chown root:wheel /usr/local/cpanel/cgi-sys/php5
# chmod +x /usr/local/cpanel/cgi-sys/php5

Step-11 Soft-linking for command-line executions:

# ln -s /usr/local/php54/bin/php-cgi /usr/local/bin/php54

Step-12 Copying php.ini from build folder

# mv /usr/local/php_source/php.ini-
production /usr/local/php54/lib/php.ini

Step-13 You need to restart httpd after the configuration 

# /etc/init.d/httpd restart

Step-14 Now everything is set. If you want to enable php5.3 for a particular account, create a .htaccess file as mentioned below.

# vi -w /home/$username/public_html/.

AddHandler application/x-httpd-php54 .php

# chown $username:$username /home/$username/public_html/.

# chmod 644 /home/$username/public_html/.

More Info..


If You Want To..
Multiple PHP Instances With One Apache
Please Check Below Link ..

I Hope You Like It..
So Enjoy..

Click Back..                                Click Home..