Installing and configuring PHP5.2, PHP5.3 and any other with FastCGI + easyApache4 and latest cPanel on CentOS

Important note: last PHP5.2 branch version was released on 6.January 2011 and is currently unsupported. It is security risk to keep running this version of PHP, as well as others, which hit end-of-life. Please keep using it on your own risk and pay attention to securing it.

The story

For a long time now cPanel has stopped supporting old PHP versions. Today oldest supported PHP version is 5.4, which has also reached end of life. But we still have many customers, who run outdated systems, custom written scripts and in general – are not able or not willing to migrate to newer version of PHP. There are several major differences between PHP 5.2 vs PHP 5.3 vs PHP 5.5 and therefore will always be someone, who will ask for old or custom-built PHP version.

Last biggest updated from cPanel in regards to apache and PHP was introduction of EasyApache4 on new servers. EasyApache4 comes with very nice handy feature of multi-php manager, that allows users to switch between PHP versions and we wanted to convert as many as possible old servers to new model. But what should customers, relaying on older PHP versions do? Should we loose them? No. There is a way to run old PHP through FastCGI interface, even though manual configuration is required.

Step 1. Install PHP5.2.

a) Download latest version of PHP 5.2.17 from here: https://secure.php.net/releases/

b) extract it, configure, build and install it. If you are not sure about what you are doing here, please ask someone for help. 🙂 Here are mine configuration options. Please note –prefix directory path – this is where binary will be installed.

'./configure'  '--disable-posix' '--enable-bcmath' '--enable-calendar' \
  '--enable-exif' '--enable-fastcgi' '--enable-ftp' '--enable-gd-native-ttf' \
  '--enable-libxml' '--enable-magic-quotes' '--enable-mbstring' \
  '--enable-pdo=shared' '--enable-soap' '--enable-sockets' '--enable-zip' \
  '--prefix=/opt/php-5.2.17' '--with-curl=/opt/curlssl/' \
  '--with-freetype-dir=/usr' '--with-gd' '--with-gettext' \
  '--with-jpeg-dir=/usr' '--with-libdir=lib64' '--with-mcrypt=/opt/libmcrypt/' \
  '--with-mysql=/usr' '--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-ttf' \
  '--with-zlib' '--with-zlib-dir=/usr' '--enable-force-cgi-redirect'

Remember to copy php.ini from source folder to /opt/php-5.2/lib/php.ini and adjust default settings, like memory_limit and disabled_functions.

Step 2. Install FastCGI module for Apache.

By default EasyApache4 does not provide FastCGI module for Apache 2.4. You should enable custom repository and install it manually. Run the following commands as root on your CentOS server:

a) Enabled experimental repository

yum install ea4-experimental

b) Install mod_fcgi for apache from experimental repository

yum install ea-apache24-mod_fcgid

Step 3. Custom configuration for Virtual Host.

You should always use include files, when you want to add custom configuration into your Apache configuration. Open your /usr/local/apache/conf/httpd.conf, search for domain, where you need custom configuration and uncomment Include line near </VirtualHost> tag. It should look like this:

Include "/etc/apache2/conf.d/userdata/std/2_4/username/mydomain.com/*.conf"

a) Create this folder for custom configuration file:

mkdir -p /etc/apache2/conf.d/userdata/std/2_4/username/mydomain.com/

b) And now create new text file inside this folder with .conf extension.

vi /etc/apache2/conf.d/userdata/std/2_4/username/mydomain.com/custom.conf

This custom configuration file should contain the following settings.

<IfModule mod_fcgid.c>
 AddHandler fcgid-script .php5 .php4 .php .php3 .php2 .phtml
 FCGIWrapper /etc/apache2/conf.d/userdata/std/2_4/username/mydomain.com/php52 .php
</IfModule>

This configuration will tell Apache to bind FCGIWrapper to php and phtml extensions. You can add more extensions here, if you need to.

Please note the path to the php52 script. It should be located in the same folder.

c) Now let’s create php52 script, that will be used as FastCGI wrapper. It is very basic and contains information which PHP binary and which configuration php.ini should be used. Please pay attention to the correct path to php-cgi and php.ini files.

#!/bin/sh
exec /opt/php-5.2.17/bin/php-cgi -c /etc/apache2/conf.d/userdata/std/2_4/username/mydomain.com/php.ini

Remember to make this file executable.

chmod +x php52

d) Copy and adjust as needed php.ini file.

cp /opt/php-5.2.17/lib/php.ini /etc/apache2/conf.d/userdata/std/2_4/username/mydomain.com/php.ini

For security I always set custom open_basedir path and set list of disabled functions (disabled_functions directive in php.ini).

open_basedir = "/home/username/public_html:/opt/php-5.2.17/lib/:/tmp"
disable_functions = "escapeshellarg, passthru, proc_close, proc_get_status, proc_nice, proc_open, proc_terminate, shell_exec, system, escapeshellcmd, exec, popen"

e) Last, but important step – set correct owner for custom configuration files.

cd /etc/apache2/conf.d/userdata/std/2_4
chown username.username username -R

Step 4. Restart Apache and enjoy.

 

Please share this article, if you find it useful. Comments and suggestions are welcome.

https://www.facebook.com/get.hosting.guru/

References:

https://documentation.cpanel.net/display/EA4/The+Experimental+Repository
https://documentation.cpanel.net/display/EA4/Apache+Module%3A+FCGId

 

Leave a Reply

Your email address will not be published. Required fields are marked *