1

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 https://stackoverflow.com/questions/524508/how-can-one-run-multiple-versions-of-php-5-x-on-a-development-lamp-server does not apply since in my case I can't use a different port - this is a regular website on the same server.

4
  • 1
    Why do you need two different PHP versions on a single website?
    – Nathan C
    Jul 4, 2013 at 12:27
  • Can you use one PHP version via CGI?
    – Sven
    Jul 4, 2013 at 12:30
  • i need to have tow versions of php for intsall osdate 2.5 Jul 4, 2013 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, 2013 at 15:51

3 Answers 3

4

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.

4
  • Will be WP (wordpress) work in such case?
    – ALex_hha
    Jul 4, 2013 at 15:23
  • I see no reason why it shouldn't.
    – Jenny D
    Jul 5, 2013 at 8:22
  • WP is very sensitive to changing of url, even port name. If you change url from site.example.com to site.example.com:8080 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, 2013 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, 2013 at 9:08
2

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 !

1

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>

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .