Running PHP 4 and PHP 5 together in vhost environment.
Folks,We are running PHP 4 right now on our servers and would like
to give people the option of experimenting/using PHP 5 if they desire.
Our system are RedHat Linux running Apache 1.3.x -- would have really
like to run both PHP 4 and PHP 5 together as modules, but that seems
to be impossible due to name conflicts.
The only other solutions we saw were to run PHP5 as CGI (which
had drawbacks), or try running a proxy server (below). Our requirements
were that it had to support multiple virtual hosts, allow people to try
out PHP5 by just giving a file a .php5 extension, support putting an
entire site on php5 and also work regardless of relative/absolute URLs
that might be used in their code.
Here is the solution we came up with, any feedback is welcome:
We decided to run a 'back' server built with PHP 5 and
responding at a unique IP address. The vhost info on this server
would be almost identical to the main servers, except for their
virtual host names,e.g.
Main Server - www.alpha.com
Back Server - php5.alpha.com
The php5.alpha.com is also added to their dns info and
resolves to the IP address of the 'back' server. All the vhosts
on that server are NameVirtualHosts.
The DocumentRoot, etc.. would be identical.
Our main servers would have a Reverse Proxy setup so that
any request for a file ending in .php5 would be sent to the Back
server for processing. (If someone wanted their whole site to switch
to PHP 5 we would just alter the rewrite conditions to accept all php
files in their vhost block). If they wanted to experiment with
seeing what their site looks like under php 5, they could go to
http://php5.alpha.com/ -- IF they used relative URL's in all their
code, they would be consistent on 5.
On our main web servers (we do virtual hosting), we added
the following in the main area of the config file:
========================
<IfModule mod_proxy.c>
RewriteEngine On
# this condition should only match on files ending in php5 (any case)
RewriteCond %{REQUEST_FILENAME} ^(.*).php5$ [NC]
# this condition picks apart the host part of the URL, we need
# to change www.alpha.com -> php5.alpha.com
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
# this rule modifies the request and submits as proxy
RewriteRule (.*)(\.php5) http://php5.%1/$1$2 [P,NC]
ProxyRequests Off
</IfModule>
=====================
In each of the vhost blocks on the main server we allow
them to inherit the rule with the following. We do have some concerns
about performance and using mod_rewrite to scan all requests, but
we will just turn on 'inherit' for the domains that want to test.
=============
RewriteEngine on
RewriteOptions inherit
=============
Any feedback is welcome, please also send me direct email at
jmurtari(at the following domain)thebook.com
Many thanks!
--
John
___________________________________________________________________
John Murtari Software Workshop Inc.
jmurtari@following domain 315.635-1968(x-211) "TheBook.Com" (TM)
http://thebook.com/