Running both PHP4 and PHP5
Sunday, 12. August 2007, 09:33:29
This sometimes causes small problems when I've used PHP5 syntax or such.
So it would be useful to have both PHP4 and PHP5 on your server so you can switch PHP4 when needed.
The solution is to run PHP4 as a CGI-script. Later in this post, I'll tell you how to enable PHP4 as a CGI script for Debian.
Why would anyone be still running PHP4? I don't know, but more servers have PHP4 running than PHP5, so it's still very common even though PHP6 is in the works!
Installing PHP4
So the things you need to have installed first is Apache 2 and PHP5. If not, you can install them with apt-get install apache2 libapache2-mod-php5.
I won't go more into the installation of that.
So how do you install PHP4 with it then? If you go the route of installing libapache2-mod-php4, it will remove PHP5 support.
Instead, do this:
apt-get install php4-cgi
This will install PHP4 as a CGI module. Next, you need to enable Apache 2 actions module:
Run a2enmod actions
Now you should have the required things installed and enabled. To add PHP4 handlers, you have two options: You can either install php4 support globally to .php4 files by editing the Apache 2 configuration or you can enable php4 for just a single directory which enables you to use the default .php extension for your files.
Configuring PHP4
Apache 2 config way:
Open /etc/apache2/apache2.conf and add these lines:
AddHandler php-script .php4
Action php-script /cgi-bin/php4
After this, all files with .php4 extension will be ran with PHP4.
Single directory way
Open .htaccess in the directory where you want to enable PHP4 support and add...
AddHandler php-script .php
Action php-script /cgi-bin/php4
This will make all .php files in the current and sub directories run with PHP4. This is quite useful since PHP does not run .php4 files by default unless separately configured to, so it saves your client (if applicable) the trouble of configuring the extensions.
You may want to install some PHP4 modules now, such as MySQL. You can do this by running apt-get install php4-mysql.