n

Archive

Switching PHP

Now with PHP5 out I wanted to run it on my test server. However, since the server the site currently runs on is "still" 4.3.7 I figured I could run them together. SitePoint's PHP Blog has a nice entry on this, however possible solutions involved running PHP5 as CGI or using different config files. Except for this solution: Parallel Instances of PHP on Windows.

This solution works quite well (for the record: I'm on a Windows box), however I'm running Apache as a service. So, I went ahead and created two services which load PHP4 and PHP5 respectively. PHP4 is the default service. I also wrote two batch files which allow you to switch. Here's how:

  1. Download and install PHP4 and PH5 for Apache 2.
  2. Where you would normally use LoadModule [PHP stuff] you now have to use this:
    <ifdefine PHP-5>
    	LoadModule php5_module "C:\PHP\php-5.0.0-Win32\php5apache2.dll"
    </ifdefine>
    <ifdefine PHP-4>
    	LoadModule php4_module "C:\PHP\php-4.3.8-Win32\sapi\php4apache2.dll"
    </ifdefine>
  3. Go to the Apache Servers Monitor in the taskbar (assuming it's running), click on it and note the name of the Apache service. Stop the service.
  4. Open the command prompt at the location of the apache.exe file and type:
    1. apache.exe -k uninstall -n "ApacheService"
    2. apache.exe -k install -n "PHP4" -D PHP-4
    3. apache.exe -k install -n "PHP5" -D PHP-5
  5. Now you can start the PHP4 or PHP5 service using the Servers Monitor.
  6. Batch files to start PHP4 or PHP5 are:
    Start PHP5
    "C:\Program Files\Apache Group\Apache2\bin\Apache.exe" -w -n "PHP4" -k stop 
    "C:\Program Files\Apache Group\Apache2\bin\Apache.exe" -w -n "PHP5" -k start
    Start PHP4
    "C:\Program Files\Apache Group\Apache2\bin\Apache.exe" -w -n "PHP5" -k stop 
    "C:\Program Files\Apache Group\Apache2\bin\Apache.exe" -w -n "PHP4" -k start

    Of course you have to verify the path to Apache.exe.

Have fun!

Comments

  1. jaman wrote:

    do you know the new version of xampp?
    i think this is the fastest way to set an apacheserver with php4 and 5, perl, mysql, phpmyadmin etc. on windows or linux.

    July 24, 2004 @ 9:38 pm. Type: Comment. Permalink.

  2. Andrew M. Johnstone wrote:

    I’m glad you like it.

    August 16, 2004 @ 12:58 pm. Type: Comment. Permalink.

  3. gunwald wrote:

    Hello everybody!

    Nice solution, but I still have a problem. PHP4 and PHP5 are using different versions of the php.ini. How can I tell Apache that it have to use different versions?

    January 18, 2005 @ 4:58 am. Type: Comment. Permalink.

  4. Andrew M. Johnstone wrote:

    I replied with a comment on my blog…

    Switching PHP
    Also defining the location of the php.ini file can now be set via…

    # configure the path to php.ini
    PHPIniDir “C:/php”
    or
    # specify the directory where php.ini is
    SetEnv PHPRC C:/php

    March 28, 2005 @ 4:05 am. Type: Comment. Permalink.

Leave a Comment

Due to some recent spam, and because this site is no longer active I've decided to disable comments side-wide. You can always mail me if you have questions. Thanks!


Navigate


Colophon

Hey! I'd like you to know that this site will be gone soon. Problems with this site (which never was intented as a final release, but has been active for some months already now) will not be solved, sorry for any inconvenience.

The future address of the new site will be http://novemberborn.net/

Summary

Running PHP4 and PHP5 easily, together, on Apache 2 (and Windows) by registering them as different Apache services.

Context


Misc.

Copyright 2003 - 2004 Mark Wubben. This website is licensed under a Creative Commons License. Powered by WordPress