Wednesday, August 27, 2014

Running Multiple PHP 5 Versions

Cpanel does not support this via direct easy apache.





To my knowledge you either need to do this manually or use CloudLinux, which offers a an addon for this purpose.


For cloud linux please follow the steps below.

http://docs.cloudlinux.com/index.html?installation.html

NB: You must have cagefs & lvemgr for this to work

http://docs.cloudlinux.com/index.html?cagefs.html

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 :D

/scripts/easyapache

Once it is done. You can proceed with the new PHP 5.4.14


Step 1:

Download the source file

mkdir /usr/local/src/php_source

cd /usr/local/src/php_source
wget http://in2.php.net/get/php-5.4.8.tar.gz/from/us1.php.net/mirror

Extract the  cource
tar -xvf php-5.4.14.tar.bz2

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/bin/apxs
The final configuration option for new install will look like the following

 ./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

 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
Installing shared extensions:     /usr/local/php54/lib/php/extensions/no-debug-non-zts-20100525/
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/

Once the installation is completed, confirm the version by using the command

#  /usr/local/php54/bin/php -v
PHP 5.4.14 (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

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.

Eg:

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.


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.

Assume that you are working on default cPanel server.

Open the file /usr/local/apache/conf/includes/pre_virtualhost_global.conf and add the following entries to enable

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/php54
Add the following contents to the above file and save
#!/bin/sh
exec /usr/local/php54/bin/php-cgi
Setting Permissions
chown root:wheel /usr/local/cpanel/cgi-sys/php54
chmod +x /usr/local/cpanel/cgi-sys/php54
Soft-linking for command-line executions:
ln -s /usr/local/php54/bin/php-cgi /usr/local/bin/php54

Copying php.ini from build folder
mv /usr/local/php_source/php.ini-production /usr/local/php54/lib/php.ini
You need to restart httpd after the configuration
/etc/init.d/httpd restart
Now everything is set. If you want to enable php5.3 for a particular account, create a .htaccess file as mentioned below.

nano -w /home/$username/public_html/.htaccess
AddHandler application/x-httpd-php54 .php

chown $username:$username /home/$username/public_html/.htaccess
chmod 644 /home/$username/public_html/.htaccess


No comments:

Post a Comment