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.

# add breezy to sources
$ sudo gedit /etc/apt/sources.list

Add the following lines to the bottom of the file:

# archive breezy repositories
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:

$ apt-get update

# 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:

/var/www/
– 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/www
$ 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:

$ sudo ln -s /var/www/php4/apache/php4.conf /etc/apache2/sites-enabled/php4

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:

$ sudo gedit /etc/hosts

Add this line to your file:

127.0.0.1 php4 php5

Step 7: Create Test Files

Open a new file in an editor:

sudo gedit /var/www/php4/www/index.php

Add this line:


Copy the file to /var/www/php5/www/:

sudo cp /var/www/php4/www/index.php /var/www/php5/www/

Step 8: Restart the Apache Server

Using apache2ctl:

sudo apache2ctl -k restart

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:

phpinfo() for php4 site
phpinfo() for php4 site

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.

Advertisements
PHP4, PHP5, One Server

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s