Although PHP 5.2 is becoming outdated, still a lot of applications and custom scripts still works on PHP 5.2. However, as per cPanel PHP 5.2 is “End of Life” and may stop offering it soon. So here is the guide for people who want PHP 5.2 along side PHP 5.3 on a cPanel server and make use of both the PHP versions at the same time.
We are assuming the default PHP version installed on your sever is 5.3.x.
1. Download and untar PHP 5.2:
# mkdir /usr/local/buildphp52 # cd /usr/local/buildphp52 # wget http://museum.php.net/php5/php-5.2.9.tar.gz # tar --strip-components=1 -zxvf php-5.2.*
2. Configure and install PHP
# ./configure --prefix=/usr/local/php52 --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.2 handlers to Apache
# pico /usr/local/apache/conf/includes/pre_virtualhost_global.conf
add the following:
Action application/x-httpd-php52 /cgi-sys/php52 AddType application/x-httpd-php52 .php52
4. Use Apache distiller for the above changes to take affect 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.2
# pico /usr/local/cpanel/cgi-sys/php52
and add the following to it
#!/bin/sh exec /usr/local/php52/bin/php-cgi
6. Set the proper ownership/permission
# chown root:wheel /usr/local/cpanel/cgi-sys/php52 # chmod +x /usr/local/cpanel/cgi-sys/php52
7. Now copy the php configuration from the build directory of PHP 5.2
# cp /usr/local/buildphp52/php.ini-production /usr/local/php52/lib/php.ini
8. Create a symlink for the PHP 5.2 executable to use from the command line:
# ln -s /usr/local/php52/bin/php-cgi /usr/local/bin/php52
9. Once done, restart Apache for changes to take affect
# service httpd restart
10. Now, PHP 5.3 will work by default and to make PHP 5.2 work for a specific account OR a folder, create a .htaccess file inside it and add the PHP 5.2 Handler
AddHandler application/x-httpd-php52 .php
That’s it. Create a phpinfo page inside the folder and browse it to see if PHP 5.2 is in effect for that folder.
Things to note is: If you want to install OR compile a module with PHP 5.2, use appropriate php-config and phpize file, i.e.
phpize: /usr/local/php52/bin/phpize php-config: ./configure --with-php-config=/usr/local/php52/bin/php-config
Comments are closed.