MySQL 5, PHP4 as CGI, with PHP5 as module on CentOS

Experts Only….(Since Apache and Mysql configuring steps not included)

Download PHp4source :

cd /usr/local/src/
wget http://some.mirror.get/php-4.4.5.tar.gz

tar -zxf php-4.4.5.tar.gz


cd php-4.4.5

./configure –prefix=/usr/local/php4 –enable-force-cgi-redirect –enable-fastcgi –with-config-file-path=/usr/local/etc/php4/cgi –with-curl –with-curl-dir=/usr/local/lib –with-gd –with-gd-dir=/usr/local/lib –with-gettext –with-jpeg-dir=/usr/local/lib –with-kerberos –with-mcrypt –with-mhash –with-mysql=/usr –with-pear –with-png-dir=/usr/local/lib –with-xml –with-zlib –with-zlib-dir=/usr/include –with-zip –enable-bcmath –enable-calendar –enable-ftp –enable-magic-quotes –enable-sockets –enable-track-vars –enable-mbstring –enable-memory-limit

You will most likely get failures that tell you which libraries you need to install, eventually, it will work. I needed to install flex and zzlib. You can always choose to remove an option above from the compile command if you can’t or don’t want to install a dependency.

Once the complie command succeeds, run:



make install

Make the php4 cgi folder and copy the compiled PHP module to the proper location:

mkdir -p /usr/local/etc/php4/cgi
cp /usr/local/src/php-4.4.2/php.ini-dist /usr/local/etc/php4/cgi/php.ini

Make a php4.conf file:

The previous PHP5 installation created a the file /etc/httpd/conf.d/php.conf- duplicate this file and rename it php4.conf, then edit the “DirectoryIndex” “Action” and “AddHandler” lines with the following information:

DirectoryIndex index.php4 index.php3
Action php4-script /cgi-bin/php
AddHandler php4-script .php3 .php4

and comment out the “LoadModule php5…” line

Create link to PHP4 in Client’s cgi-bin Directory
# Due to Security Issues the PHP4 CGI is installed at /usr/local/etc/php4/cgi/php.ini. In the Interworx virtual host setup using suexec, each user has their own cgi-bin. Do the following to link the PHP4 CGI into your hosting client’s cgi-bin directory.

cd /chroot/home/client/public_html/cgi-bin (ie:virtual host document root or the alias path of your site)
ln /usr/local/php4/bin/php php
chown client php
chgrp client php
chmod 755 php

Test your PHP installation
try creating a doc for both versions of PHP:

This  can be your virtualhost document root or the alias path of your site.

using the same code:


The phpinfo() function reports the version number, as well as the features that are compiled into PHP. You’ll see that info.php4 uses php4 and info.php5 uses php5.

.htaccess Instructions:
Instruct your customers to create .htaccess files when they want to force php4 to be used on their site, or in just certain folders:

Customers just need to place that .htaccess file in the ../public_html folder or whatever folder they want php4 to be used instead of the default handler for the server, PHP5, which is stipulated in /etc/httpd/conf.d/php.conf.

Wherever you customer puts this .htaccess file, PHP4 will be used on that folder and any of that folder’s sub-folders.

The .htaccess file should read:

Options + FollowSymlinks
Action php-script /cgi-bin/php
AddHandler php-script .php

Sub-Domain Issues with PHP as a CGI:

Placing an .htaccess file like the one above in a sub-domain folder doesn’t work! Your choice’s are:

1. Place the .htaccess file above in the client’s root site folder (/html/.htaccess) do that PHP4 is used on the entire site
2. Don’t use sub-domains (use as long as the folder isn’t a subdomain placing the .htaccess file above will apply php4 to that folder and it’s sub-folders only.

Option 1 isn’t as bad as it sounds- because php5 is an apache module, you can enable it on any folder (subdoamin or regular subfolder) using the .htaccess code below.You just have to realize that any individual files in the site’s root level (like index.php ) are going to be stuck with PHP4.

Quick summary:
1. Place the .htaccess file above in the client’s /html folder- now their site uses php4 by default
2. Any folders you wish to override with PHP5 must have the following .htaccess file at the sub-domain/sub-folder’s root (/html/subdomain_folder/.htaccess) using this syntax:

Options +FollowSymlinks
AddHandler php5-script .php
AddType text/html .php

Published in: on January 30, 2010 at 2:58 pm  Comments Off on MySQL 5, PHP4 as CGI, with PHP5 as module on CentOS  
%d bloggers like this: