How to Install Old and New Versions of PHP on the cPanel Server?

July 28, 2014 / FAQs

PHP 5.2 has become outdated and 5.3 is officially mentioned as “End of Life” status. But many applications and custom scripts still work on these two platforms. So here is the guide for people who wish to use PHP 5.2 or 5.3 along with PHP 5.4 or 5.5 on a cPanel server and make use of both versions at the same time.

Let’s assume the latest version of PHP 5.4 is installed on your server by default. But for some reason, you need to install an older version; follow the below steps to install an old version of PHP.

  1. Download and untar the older version of PHP that you wish to install. Here we assume that you are willing to install 5.3:
    # mkdir /usr/local/buildphp53
    # cd /usr/local/buildphp53
    # wget
    # tar --strip-components=1 -zxvf php-5.3.*
  2. Configure and install PHP
    #./configure --prefix=/usr/local/php53 --enable-cgi --enable-bcmath
     --enable-calendar --with-mysql=/usr/bin -with-libdir=lib64 --with-gd
     --enable-mbstring (you can add more modules per your wish)
    # make
    # make install
  3. Now add the PHP 5.3 handlers to Apache
    # pico /usr/local/apache/conf/includes/pre_virtualhost_global.conf

    Add the following:

    Action application/x-httpd-php53 /cgi-sys/php53
    AddType application/x-httpd-php53 .php53
  4.  Use Apache distiller for the above changes to take effect and make cPanel skip .htaccess scan and remove the mime types:
    # /usr/local/cpanel/bin/apache_conf_distiller --update
    # touch /var/cpanel/easy_skip_update_php_mime_types
  5.  Now create a file under the cgi-sys directory of cPanel so it detects PHP 5.3
    # pico /usr/local/cpanel/cgi-sys/php53

    And add the following to it

    exec /usr/local/php53/bin/php-cgi
  6.  Set the proper ownership/permission
    # chown root:wheel /usr/local/cpanel/cgi-sys/php53
    # chmod +x /usr/local/cpanel/cgi-sys/php53
  7.  Now copy the PHP configuration from the build directory of PHP 5.3
    # cp /usr/local/buildphp53/php.ini-production/usr/local/php53/lib/php.ini
  8.  Create a symlink for the PHP 5.3 executable to use from the command line:
    # ln -s /usr/local/php52/bin/php-cgi /usr/local/bin/php53
  9.  Once done, restart Apache for changes to take effect:
    # service httpd restart
  10.  Now, PHP 5.4 will work by default and to make PHP 5.3 work for a specific account OR a folder, create a .htaccess file inside it and add the PHP 5.3 Handler
    AddHandler application/x-httpd-php53.php

That’s it. Create a phpinfo page inside the folder and browse it to see if PHP 5.3 is in effect for that folder.

Things to note is: If you want to install OR compile a module with PHP 5.3, use the appropriate php-config and phpize file, i.e.

phpize: /usr/local/php53/bin/phpize
php-config: ./configure --with-php-config=/usr/local/php53/bin/php-config