Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have read this topic: Running php4 and php5 along side each other

There, the issue is handling two different generations of PHP (PHP 4 vs PHP 5), but what I need is to make all but one of my server accounts work under 5.3 and just a single domain under 5.2.

I cannot make this through Apache models, and the answer from does not apply since in my case I can't use a different port - this is a regular website on the same server.

share|improve this question
Why do you need two different PHP versions on a single website? – Nathan C Jul 4 '13 at 12:27
Can you use one PHP version via CGI? – Sven Jul 4 '13 at 12:30
i need to have tow versions of php for intsall osdate 2.5 – Islam Baraka Jul 4 '13 at 13:45
Serious deployments (a.k.a. not-PHP applications) quite often require different versions of interpreter and libraries in a shared hosting configuration, nothing weird. – fsoppelsa Jul 4 '13 at 15:51
up vote 4 down vote accepted

You can still use the answer in; 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>
   ProxyPass /
   ProxyPassReverse /

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.

share|improve this answer
Will be WP (wordpress) work in such case? – ALex_hha Jul 4 '13 at 15:23
I see no reason why it shouldn't. – Jenny D Jul 5 '13 at 8:22
WP is very sensitive to changing of url, even port name. If you change url from to the WP wouldn't work. Other the most common CMS like - Drupal, Joomla, Magento is less sensitive, as far as I know – ALex_hha Jul 5 '13 at 8:50
Given that, I can make no guarantees - but the point here is that you should not change the URL; the proxy setup is specifically so you can keep the old URL even though the server is in fact running on another port. But we're now getting onto a territory that I'm less familiar with. – Jenny D Jul 5 '13 at 9:08

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/

# 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

# 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


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 !

share|improve this answer

I just used cgi for such case

<VirtualHost *:80>
    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
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.