Long story short… I needed a way for a specific folder to use PHP 5.3 and to keep using PHP 5.2 for the rest of the system, and I needed to do this without breaking the existing CPanel (blergh) configuration (Luckily the system was already using suphp – if yours isn’t just change it using easyapache) .

In the end it was easier than I thought…

  1. Compile and install PHP 5.3 to a folder under /opt
  2. Add Application Handler to Apache Configuration
  3. Add Handler to htaccess on the folders I needed the PHP5.3 (this could also be done within the VHost config)

Read the rest of the post for the full details

cd /usr/src

wget http://us.php.net/get/php-5.3.8.tar.gz/from/this/mirror

tar xfz php-5.3.8.tar.gz

cd php-5.3.8
./configure
–enable-bcmath
–enable-calendar
–enable-exif
–enable-ftp
–enable-gd-native-ttf
–enable-libxml
–enable-magic-quotes
–enable-mbstring
–enable-pdo=shared
–enable-soap
–enable-sockets
–enable-zend-multibyte
–prefix=/opt/php53
–with-bz2
–with-config-file-path=/opt/php53/lib
–with-config-file-scan-dir=/opt/php53/lib/php.ini.d
–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-libxml-dir=/opt/xml2
–with-libxml-dir=/opt/xml2/
–with-mcrypt=/opt/libmcrypt/
–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-png-dir=/usr
–with-pspell
–with-sqlite=shared
–with-xpm-dir=/usr
–with-zlib
–with-zlib-dir=/usr
–with-libdir=lib64

make

make install

cp php.ini-production /opt/php53/lib/php.ini

Don’t forget to change your options on the previous file (like timezone)

Edit /opt/suphp/etc/suphp.conf, look for the line containing “application/x-httpd-php5” and add the following line after it:

application/x-httpd-php53=”php:/opt/php53/bin/php-cgi”

Edit /usr/local/apache/conf/includes/post_virtualhost_global.conf:

suPHP_AddHandler application/x-httpd-php53

Now you just need to add:

AddHandler application/x-httpd-php53 .php

to an .htaccess on the folders you need to use with PHP5.3