Community day

At the eZ Winter Conference 2010, meet up with the community in Geneva, jan. 21st.
Register and read more here.

Multiple Apache Installations HOWTO

In this short article I will explain how to set-up two versions of Apache/PHP on one system.

Configuring Multiple Apache Installations

Because two Apache installations can not be installed into the same path, you have to use a different installation prefix for each different installation. In the examples that I show here I will compile PHP as a static module to Apache, as that is the best performing combination. It will take a little bit more time (15 seconds) to compile Apache too when upgrading PHP, but I can live with that.

Below I show a example configuration and compilation session of Apache and PHP. Everything in bold is something that you need to differ between different Installations on the same system.

cd apache-1.3.31
 
./configure --prefix=/usr/local/php43
 
cd ..
 
cd php-4.3.11
 
./configure --prefix=/usr/local/php43 --with-apache=/dat/src/apache-1.3.31 <other options>
 
make
<|!REG3XP0!>
make install
 
cd ..
 
cd apache-1.3.31
 
./configure --prefix=/usr/local/php43 --activate-module=src/modules/php4/libphp4.a --enable-module=rewrite --enable-module=proxy <other options>
 
make
|>
make install

After setting it up for PHP 4.3, you can repeat the process above but change the 4.3.11 and /local/local/php43 to reflect PHP 4.4.

Allowing Multiple Apache Installations Running at the Same Time

Normally Apache runs on port 80 and it is impossible to have two Apache instances using this same port of course.
The easiest way is by allowing two IP addresses to be bound to one server, but using different ports in combination with a proxy server works as well ofcourse. In the setup on my development machines I simply use different ports for different Apache/PHP versions, such as :14311 for PHP 4.3.11 and :1510 for PHP 5.1.0-dev.

Two IP Address Setup

As you now have two different configuration files, one as /usr/local/php43/conf/httpd.conf and one as /usr/local/php44/conf/httpd.conf you can make your adjustments there. For example if you have two different IP addresses - one for each Apache installation you can use this:

Listen 10.0.2.35:80

This will cause Apache only to bind to one of the IP addresses on the machine (10.0.2.35 in my example, but ofcourse you need to use an IP addresseble address like 212.204.192.51 here), and only to port 80. In the other installations' configuration you need to select the other IP:

Listen 10.0.2.36:80

You also need to update your DNS according to where you placed the vhost for a specific site.

One IP - Multiple Ports and mod_proxy

If your server does not have the possibility to have more than one IP address, then you can deply a different setup. In this setup the configuration on the PHP 4.3 server contains all vhosts, but for the ones that are already moved to the PHP 4.4 server special apache configuration settings are added to redirect internally from the PHP 4.3 server to the PHP 4.4 one.
The configuration for the PHP 4.3 server should have the following statements:

Listen 10.0.2.35:80
 
NameVirtualHost 10.0.2.35.80

The listen statement for the PHP 4.4 server should be modified to that it listens at a different port than port 80:

Listen 127.0.0.1:8044
 
NameVirtualHost 127.0.0.1:8044

The vhost configuration of one of the sites that was moved to the PHP 4.4 server now looks in the PHP 4.3 server like:

<VirtualHost 10.0.2.35:80>
 
ServerName site1.example.com
 
DocumentRoot /usr/local/htdocs/ezpublish-site1
 
RewriteEngine On
 
RewriteRule !\.(gif|css|jpg|png|jar|ico|js)$ /index.php
 
</VirtualHost>
 
<VirtualHost 10.0.2.35:80>
 
ServerName site2.example.com
 
ProxyPass / http://site2internal:8044/
 
</VirtualHost>

And in the PHP 4.4 server configuration like:

<VirtualHost 127.0.0.1:8044>
 
ServerName site2internal
 
DocumentRoot /usr/local/htdocs/ezpublish-site2
 
RewriteEngine On
 
RewriteRule !\.(gif|css|jpg|png|jar|ico|js)$ /index.php
 
</VirtualHost>

You need to make sure that site2internal is configured in your /etc/hosts file:

127.0.0.1  localhost site2internal

This should be all that you have to do in to run PHP 4.3 and PHP 4.4 concurrently. (Or any two other PHP versions ofcourse).

Latest comments

No comments yet!

You must be logged in to post comments.

Derick Rethans

Derick Rethans works as project leader for the eZ Components project and has contributed in a number of ways to the PHP project, including the mcrypt, date and input-filter extensions, bug fixes, additions and leading the QA team. In his spare time he likes to work on Xdebug, watch movies, travel and practice photography.

Powered by eZ Publish® Content Management System. Copyright © 2009 eZ Systems AS (except where otherwise noted). All rights reserved.