Running two PHP versions (5.3 & 5.2) at the same time

You can still use the answer in https://stackoverflow.com/questions/524508/how-can-one-run-multiple-versions-of-php-5-x-on-a-development-lamp-server; you just need to add a way to redirect that traffic to the other port. Here's how:

You set up a separate apache instance with PHP 5.2, and you set it to listen to port 8080.

On your regular apache, you change the VirtualHost for that one domain so that it now contains a reverse proxy to the 5.2 apache. Example:

<VirtualHost *:80>
   Servername php52.example.com
   ProxyPass / http://yourservername.example.com:8080/
   ProxyPassReverse / http://yourservername.example.com/
</VirtualHost> 

That way, your original apache instance will accept all traffic to all websites on your server. But requests to this one particular domain will be transparently forwarded to the other instance without the user on the other side of the browser knowing it.


There is a way to achieve this on a per-directory basis. You do find contradicting opinions on the web, but I have been able to make it work.

First, you must organize to have your different versions of PHP ready to run as CGI or fastCGI extentions. I use fastCGI in the example below

You will need to set up two separate php.ini files (and yes, maintaining them in sync where it matters can be a pain, but the alternative is to have only one php.ini file for 2 different versions of PHP & that's either impossible or full of loopholes)

Place those php.ini files in the directory of your PHP code, modules, etc. one for each version. This is where PHP will go look for them first, absent the PHPRC environment variable. You should not set the PHPRC variable, unless you discover how to make it different for 2 different fastCGI stubs, I have not been able to: the Apache FcgidInitialEnv directive works only globally, not on a per-directory basis, and the FcgidCmdOptions which is supposed to does not work at all.

Then, all you have to do is to add the following code in you httpd.conf file:

#
# start PHP as FastCGId
#

LoadModule fcgid_module modules/mod_fcgid.so

#
# PHP 7.0 is the default
# PHP 5.2 is the legacy
#

<Files ~ "\.php$>"
  AddHandler fcgid-script .php
  FcgidWrapper "c:/WebServers/PHP-7.0.5/php-cgi.exe" .php
</Files>

#
# Keep PHP 5.2 for legacy Drupal sites
#
<DirectoryMatch "Puitscarre|Royale$">

  <Files ~ "\.php$>"
    AddHandler fcgid-script .php
    FcgidWrapper "c:/WebServers/PHP-5.2.39/php-cgi.exe" .php
  </Files>

</DirectoryMatch>

It works perfectly on my environment: Windows 7, Apache 2.2. And, by the way, the code that is in the Directory environment above also works if you put it in the .htaccess file of the directories which need a specific or legacy version of PHP

Enjoy !


I just used cgi for such case

<VirtualHost *:80>
    Servername site.example.net
    ScriptAlias /php-fastcgi/ /usr/local/php-5.2.17/bin/

    AddHandler php-fastcgi .php
    AddType application/x-httpd-php .php
    Action php-fastcgi /php-fastcgi/php-cgi
...
</VirtualHost>