How to use mod_php4 and mod_php5 in parallel

There are several possibilities to use mod_php4 and mod_php5 in parallel on the same Apache 1.3.x server. For example, if you have plenty of free IPs, you could just set up a new nameserver entry to assign two host names to two different IPs and then use two Apache instances, both running on port 80 and grabbing one of those two IPs.

Another possibility is to use only one IP, two Apache installations, mod_proxy and mod_rewrite: configure the first Apache to run on port 80 and use mod_php4, for example. The second Apache, located at /usr/local/apache-php5/ (or whereever you place it), will run on another port (i.e. port 5555 or something like that) and have mod_php5 compiled with it (so when compiling PHP5, you have to use –with-apxs=/usr/local/apache-php5/bin/apachectl).

You configure the second apache to have it’s PHP5 host:

NameVirtualHost IP:5555

<VirtualHost IP:5555>
Port                     5555
DocumentRoot        /my/docroot

If you access and have a phpinfo.php for example, you will see PHP5 running on it.

The first Apache on port 80 has a special VirtualHost entry to tunnel it to the front:

<VirtualHost IP>
Port                    80
RewriteEngine           On
RewriteRule             ^/(.*)$1 [P]

You use the proxying mechanism in combination with mod_rewrite to get it through. The user on the front doesn’t see anything that the PHP5 vhost originally runs on port 5555. Remember to filter requests on 5555 in your firewall :-)

Any other ideas? Let me know.

Für neue Blogupdates anmelden:

3 Gedanken zu „How to use mod_php4 and mod_php5 in parallel

  1. I’ve done this, in the past, but with a few changes:

    – I’ve set up a number of IPs, and bound them to the loopback interface, only. This allows proxying to any number of IP addresses, on port 80 (from localhost). Your way is fine, but if you have one point of contact (mod_proxy listening on port 80 of your „real“ IP), then you KNOW that your other instances are proxied, and they’re running on the native port.

    – If the first sounds like too much work, you can still bind only to localhost on stray ports (nearly what you did). This allows pushing everything throughh mod_proxy, but without the headache of maintaining IPs.

    – You should be able to alter your apachectl to point at different httpd.conf files. You’ll need to make sure you segregate your Scoreboard and PID directives, but this will allow you to maintain only a single Apache installation (but multiple instances of said installation).

    – If you have everything on public interfaces (contrary to my first two points) You could use mod_rewrite with the [R] directive. This would actually redirect your users, reducing the load on your server, but it’s probably negligible.

    – And my last thought: don’t forget that $_SERVER[‚REMOTE_ADDR‘] (and REMOTE_HOST) will report your proxy for all proxied requests. You’ll want $_SERVER[‚X_FORWARDED_FOR‘].


    • The ZE1 Compatibility mode does a few changes in how the Engine works but it doesn’t give you 100% compatibility. So for some applications it might be enough but not all applications would still work and still need PHP4.

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht.