How to use mod_php4 and mod_php5 in parallel

Avatar von Björn Schotte

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
ServerName           php5.domain.de
DocumentRoot        /my/docroot
</VirtualHost>

If you access http://php5.domain.de:5555/ 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
ServerName              php5.domain.de
RewriteEngine           On
RewriteRule             ^/(.*) http://php5.domain.de:5555/$1 [P]
</VirtualHost>

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.

Avatar von Björn Schotte

Kommentare

3 Antworten 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‘].

    S

  2. A more easy way is to use php 5 and put this wherever php 4 is needed in httpd.conf or .htaccess:

    php_flag zend.ze1_compatibility_mode on

    1. 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. Erforderliche Felder sind mit * markiert


Für das Handling unseres Newsletters nutzen wir den Dienst HubSpot. Mehr Informationen, insbesondere auch zu Deinem Widerrufsrecht, kannst Du jederzeit unserer Datenschutzerklärung entnehmen.