PHP4, PHP5, One Server
I posted last month on running PHP4 and PHP5 independently on separate local domains on a single Apache server under Ubuntu. This post updates my original post.
The goal here is to create two domains:
http://php5/ — running PHP5 via an Apache module
http://php4/ — running PHP4 through CGI
The steps below are adapted from the guide found here:
http://www.howtoforge.com/apache2_with_php5_and_php4
Step 1: Install LAMP Server Including Apache2 and PHP5
If you haven’t already done this, you can just follow the normal steps using apt-get as outlined here:
https://help.ubuntu.com/community/ApacheMySQLPHP
Step 2: Update Sources List to Install php4-cgi
php4 is no longer included in the Ubuntu repositories as it is no longer supported. But it can be found in the breezy repositories. This was the step that took me the longest to figure out as there were no explicit instructions regarding this.
$ sudo gedit /etc/apt/sources.list
Add the following lines to the bottom of the file:
deb http://old-releases.ubuntu.com/ubuntu/ breezy-updates main restricted
deb http://old-releases.ubuntu.com/ubuntu/ breezy-security main restricted
deb http://old-releases.ubuntu.com/ubuntu/ breezy main restricted
deb http://old-releases.ubuntu.com/ubuntu/ breezy universe
deb http://old-releases.ubuntu.com/ubuntu/ breezy-security universe
Step 3: Install php4-cgi
Run the following commands from the command line:
# safety first: back up your main apache2 config file
$ sudo cp /etc/apache2/apache2.conf /tmp/apache2.conf
# install php4-cgi
$ sudo apt-get install php4-cgi
# install php4 packages
$ sudo apt-get install php4-curl php4-domxml php4-gd php4-imap php4-ldap php4-mcal php4-mcrypt php4-mhash php4-mysql php4-odbc php4-snmp php4-xslt curl libwww-perl imagemagick
Step 4: Create Your Document Roots
You can put the document roots for your http://php5/ and http://php4/ sites anywhere. For lack of a better general location, I am going to put them under the standard /var/www/ directory. The directory tree will look like so:
– php5/
– apache/ <-- apache config file goes here
- www/ <-- document root
- php4/
- apache/ <-- apache config file goes here
- www/ <-- document root
Commands:
$ sudo mkdir -p /var/www/php5/apache
$ sudo mkdir -p /var/www/php4/www
$ sudo mkdir -p /var/www/php4/apache
Step 5: Configure Apache Sites
First, for the php4 site, add to the /var/www/php4/apache directory the file found here:
http://klenwell.googlecode.com/svn/trunk/templates/apache/php4.conf
Then enable this site, by linking the config file to apache’s sites-enabled directory:
Do the same thing with the php5 file (found here) in the /var/www/php5/apache directory.
Step 6: Create Local Domain php4 and php5 in /etc/hosts
Open up your hosts file in the editor:
Add this line to your file:
Step 7: Create Test Files
Open a new file in an editor:
Add this line:
<?php phpinfo(); ?>
Copy the file to /var/www/php5/www/:
Step 8: Restart the Apache Server
Using apache2ctl:
Finally, test the results by opening the following two urls in your browser:
http://php5/
http://php4/
You should see the PHP Info page for each site displaying the appropriate PHP version. For the php4 site, it should look something like this:
If that all works, you are ready to adapt as suits you. You can link any php4 projects you are working on to the php4/www directory.
The same principles should apply to other systems and circumstances, though you’ll have to work out the details for yourself.
This guide generalizes details of my own successful installation. If you try this and have any issues, please leave a comment here.
