PHP 5.2 and PHP 5.3 side by side in cPanel servers

I just got a customer that needs both php 5.3 and php 5.2 in the server for various reasons, so here’s how it works:

1 – You need to compile php5.2 from EasyApache

2 – mkdir /usr/local/buildphp53/ ; cd /usr/local/buildphp53/ ; wget http://cz2.php.net/get/php-5.3.27.tar.gz/from/us1.php.net/mirror ; tar zxf php-5.3.27.tar.gz ; cd php-5.3.27/

3 – Modify the configure line below to suit you:

./configure –enable-bcmath \
–enable-cgi \
–enable-calendar \
–enable-exif \
–enable-ftp \
–enable-gd-native-ttf \
–enable-libxml \
–enable-magic-quotes \
–enable-mbstring \
–enable-pdo=shared \
–enable-sockets \
–enable-zip \
–prefix=/usr/local/php53 \
–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-mhash=/opt/mhash/ \
–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-sqlite=shared \
–with-tidy=/opt/tidy/ \
–with-xmlrpc \
–with-xpm-dir=/usr \
–with-zlib \
–with-zlib-dir=/usr

4 – make && make install

5 – Go to Apache configuration in WHM, and edit /usr/local/apache/conf/includes/pre_virtualhost_global.conf

Add the lines below, save and restart apache.

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

 AddType application/x-httpd-php53 .php53

6 – Have apache skip the htaccess scan and remove mine types:

/usr/local/cpanel/bin/apache_conf_distiller –update

touch /var/cpanel/easy_skip_update_php_mime_types

7 – Create a new file and add the lines below to it: /usr/local/cpanel/cgi-sys/php53

#!/bin/sh
 exec /usr/local/php53/bin/php-cgi

8 – Permissions:

chown root:wheel /usr/local/cpanel/cgi-sys/php53

chmod +x /usr/local/cpanel/cgi-sys/php53

9 – Linking:

 ln -s /usr/local/php53/bin/php-cgi /usr/local/bin/php53

10 – php.ini:

mv /usr/local/buildphp53/php-5.3.27/php.ini-production /usr/local/php53/lib/php.ini

Restart apache

Running php 5.3 :

Add this into a .htaccess file located in the public_html folder in the user’s account that you want it to run on.

AddHandler application/x-httpd-php53 .php

Magento not working on PHP 5.3

I have upgraded today to php 5.3.1, and obviously, issues started to arise. I have a customer using Magento, so he got the error below, when accessing his store:

Fatal error: Method Varien_Object::__tostring() cannot take arguments in /magento/lib/Varien/Object.php

Quick fix actually:

File: /lib/Varien/Object.php (Line 484)

Change from:

public function ___toString(array $arrAttributes = array(), $valueSeparator=’,’)

to:

public function __invoke(array $arrAttributes = array(), $valueSeparator=’,’)

AND

File /app/code/core/Mage/Core/Controller/Request/Http.php (Line 199)

Change from:

$host = split(’:’, $_SERVER[‘HTTP_HOST’]);

to:

$host = explode(’:’, $_SERVER[‘HTTP_HOST’]);

And there you go. Make sure you make both mods, otherwise it will not work.