Different PHP versions per Apache virtual host

Problems with the Linux version of XAMPP, questions, comments, and anything related.

Different PHP versions per Apache virtual host

Postby npardoe » 03. September 2009 12:09

Hi all,

I'm running XAMPP 1.7.2 on Ubuntu 8.10 (Linux dt19.im.local 2.6.27-14-generic #1 SMP Tue Aug 18 16:25:45 UTC 2009 i686 GNU/Linux) and am using the PHP 5.3.0 Apache module as standard. For one virtual host I'd like to use PHP 5.2.X as it is part of a project which has a lot of legacy code which is not compatible with PHP 5.3.0. The virtual host configuration block and the applicable directory directive are as follows -

Code: Select all
<VirtualHost 127.0.0.1:80 192.168.1.28:80>
    ServerAdmin [SNIP]
    DocumentRoot htdocs/[SNIP]/[SNIP]
    ServerName [SNIP].localhost
    ServerAlias www.[SNIP].localhost
    ErrorLog logs/[SNIP]-error_log
    CustomLog logs/[SNIP]-access_log common
    # Must use PHP <5.3.0 (5.2.6 in production use)
    # PHP 5.3.0 MySQL library drops support for <MySQL 4.1 password hashes which are used by the [SNIP] database
    Action application/x-httpd-php "cgi-bin/php-5.2.6 -c /opt/lampp/etc/php.ini-pre1.7.2"
    AddHandler application/x-httpd-php .php
</VirtualHost>

# Permissions required here even though cgi-bin has the +FollowSymLinks option set
# FollowSymLinks doesn't change the pathname matched against <Directory> sections
# See http://httpd.apache.org/docs/2.0/mod/core.html#options
<Directory /opt/lampp/bin>
  AllowOverride None
  Options +ExecCGI

  <Files php-5.2.6>
    Order allow,deny
    Allow from all
  </Files>
</Directory>


Checking phpinfo() output on the above virtual host (or using the default virtual host directive and accessing it via http://localhost/[SNIP]/[SNIP]/phpinfo.php rather than http://[SNIP].localhost/phpinfo.php) shows PHP 5.3.0 is running. After applying minor tweaks such as adding ScriptAlias or SetEnv options the problem persists. I've Googled for a good while and have checked the permissions and the like and tried the advice of other users (XAMPP or otherwise) either resulting in PHP 5.3.0 being used or a HTTP 400 bad request/invalid URI error. I've stuck with the configuration above as this is correct according to the PHP manual.
FYI cgi-bin/php-5.2.6 is a soft symbolic link to /opt/lampp/bin/php-5.2.6 (I've added the FollowSymLinks option to the cgi-bin directory directive in httpd.conf). I've tried installing php5-cgi from the Ubuntu repos and setting it up in a similar way, to no avail. I've also tried copying the executables into the cgi-bin directory, pointing the Action line directly to bin/php-5.2.6 and dropping the -c /opt/lampp/etc/php.ini-pre1.7.2 option in the Action line. I've even tried commenting out the LoadModule lines for PHP which results in a HTTP 400 bad request/invalid URI error. This demonstrates the fact that the PHP CGI use is being ignored.

Any help or pointers would be appreciated. I've checked httpd.conf and the extra/httpd-*.conf files and ensured all required includes are being loaded. I know that it's probably something stupid on my part which is causing this!

Thanks in advance for the assistance :)
Best regards,

Nathan Pardoe
npardoe
 
Posts: 2
Joined: 03. September 2009 11:50

Re: Different PHP versions per Apache virtual host

Postby dmphotography » 12. September 2009 18:26

npardoe,
I will go ahead and tell you it's probably very unlikely that someone is going to find the answer to this if they themselves haven't needed it. The reason being is because someone would have to spend a couple of hours doing it themselves to figure it out and there's a better solution for what you're trying to do.

Download XAMPP 1.7.1 from here: http://sourceforge.net/projects/xampp/files/XAMPP%20Linux/1.7.1/

Now just simply extract it to a different folder than your XAMPP 1.7.2 version.

Make sure XAMPP 1.7.2 is completely stopped, then start XAMPP 1.7.1.

Now you can run your script in XAMPP 1.7.1 and it's using PHP 5.2.8. If you need XAMPP 1.7.2, just simply stop XAMPP 1.7.1, then start XAMPP 1.7.2.

That's the easiest solution.
For great video and written tutorials and guides on creating your own web server and installing things such as forums, blogs, etc., visit http://myownhomeserver.com
dmphotography
 
Posts: 191
Joined: 15. December 2008 14:25
Location: Columbus, MS
Operating System: Windows 7

Re: Different PHP versions per Apache virtual host

Postby npardoe » 14. September 2009 09:28

dmphotography wrote:npardoe,
I will go ahead and tell you it's probably very unlikely that someone is going to find the answer to this if they themselves haven't needed it. The reason being is because someone would have to spend a couple of hours doing it themselves to figure it out and there's a better solution for what you're trying to do.

Download XAMPP 1.7.1 from here: http://sourceforge.net/projects/xampp/files/XAMPP%20Linux/1.7.1/

Now just simply extract it to a different folder than your XAMPP 1.7.2 version.

Make sure XAMPP 1.7.2 is completely stopped, then start XAMPP 1.7.1.

Now you can run your script in XAMPP 1.7.1 and it's using PHP 5.2.8. If you need XAMPP 1.7.2, just simply stop XAMPP 1.7.1, then start XAMPP 1.7.2.

That's the easiest solution.


Thanks for your reply dmphotography. I think you're right - simplest solution is to have two XAMPP installations. Thanks a million for the help :)
Best regards,

Nathan Pardoe
npardoe
 
Posts: 2
Joined: 03. September 2009 11:50

Re: Different PHP versions per Apache virtual host

Postby dmphotography » 14. September 2009 09:40

One other thing you could take a look at is my "crossover" method.
http://tinyurl.com/xampp172-crossover

What I did was already have XAMPP 1.7.2 installed, then downloaded and installed XAMPP 1.7.1 as well.
I went in and changed a few small configuration settings to where I could run XAMPP 1.7.2's MySQL server and XAMPP 1.7.1's Apache server and have them both sharing the same htdocs folder.

This way all I have to do to switch between PHP 5.2.8 and PHP 5.3 is stop one Apache server and start the other one. This allows me to have two PHP environments while sharing the same MySQL database and htdocs folder. I really wish I could figure out how to add PHP 5.2.10 to XAMPP 1.7.2, but I spent several hours and had no success, so unless someone else wants to step up to the challenge, this is the easiest solution I've found so far.

I hope that helps.
For great video and written tutorials and guides on creating your own web server and installing things such as forums, blogs, etc., visit http://myownhomeserver.com
dmphotography
 
Posts: 191
Joined: 15. December 2008 14:25
Location: Columbus, MS
Operating System: Windows 7


Return to XAMPP for Linux

Who is online

Users browsing this forum: No registered users and 16 guests