X

PHP 5.2 in cPanel easy apache 4

PHP 5.2 in removed from cPanel’s easy apache 4 for quite some time. However you can get it to run using a CGI handler.  This isn’t really recommended as newer versions of PHP offer both better performance and security when PHP 5.2 went end of life.  That said, certain old code wont work without and if you are in a rush this will get you through it.

First SSH into the server and sudo to root to get started.

Obtain and compile php 5.2

Then go to a install directory and get the last php 5.2 release:

cd/usr/src; wget http://museum.php.net/php5/php-5.2.17.tar.gz;

Next get the patch for php-5.2.17 so it will compile on modern releases:

wget -O /usr/src/php-5.2.17.patch https://mail.gnome.org/archives/xml/2012-August/txtbgxGXAvz4N.txt

Then uncompress the php package:

tar xfvz php-5.2.17.tar.gz;

Navigate to the uncompressed directory:

cd php-5.2.17;

Apply the patch to the php install:

patch -p0 < ../php-5.2.17.patch;

Next go ahead and configure php,I used the following configure options:

 ./configure  --prefix=/opt/php52  --enable-force-cgi-redirect  --enable-fastcgi  --with-regex=php  --enable-calendar  --enable-sysvsem  --enable-sysvshm  --enable-sysvmsg  --enable-bcmath  --enable-ctype  --with-iconv  --enable-exif  --enable-ftp  --with-gettext  --enable-mbstring  --with-pcre-regex  --enable-shmop  --enable-sockets  --enable-wddx  --with-libxml-dir=/usr  --with-zlib  --with-openssl  --enable-soap  --enable-zip  --with-gd  --with-mysql  --with-mysqli  --with-pdo-mysql  --with-pear  --with-jpeg-dir=/usr  --enable-gd-native-ttf  --with-ttf  --with-freetype-dir=/usr  --with-libdir=lib64

then make and install php 5.2:

make && make install

Create the needed files for cPanel

create /usr/local/cpanel/cgi-sys/php52 and add the following code:

#!/bin/sh
exec /opt/php52/bin/php-cgi

Save it and change the permissions:

chmod 755 /usr/local/cpanel/cgi-sys/php52

Add to the following to the .htaccess of the domain you want to be in php 5.2:

AddHandler php-script .php
Action php-script /cgi-sys/php52

That will complete the setup. Finally make a test file in the document root to make sure it works

<?PHP
phpinfo();
?>

 

This build will be independent of easy Apache and should persist through updates successfully.

LinuxAdmin.io
0 0 votes
Article Rating
LinuxAdmin.io:

View Comments (4)

Related Post