Core PHP
Apache 2, PHP 4 & PHP 5 on Windows XP
Core PHP
Blog: CorePHP Blog     Current Projects: PHP on XP Guide  —  NFO Viewer  —  Easy Reflections  —  HotWire  —  FileGlider
< Previous Index Next >

Step 17 - Running PHP 4 and 5 together

It is possible to configure Apache so that you can run PHP 5 as an Apache Module and PHP 4 as CGI, at the same time, with no messing around with proxies, silly extensions (like .php4 / .php5), or different port numbers.

It's actually very easy to achieve. The following instructions show how:

PHP 4 as CGI and PHP 5 as a Module

1) Edit the Apache httpd.conf file and ensure that the following LoadModule line is uncommented (this is the default after an Apache installation, but do check it anyway):

LoadModule actions_module modules/mod_actions.so

2) Locate the block of text in the httpd.conf that tells Apache to use PHP 5. Make sure that PHP 4 is commented out (or simply delete those two lines totally) and add the Directory section after it. The final result should look like this:

... all the other LoadModule lines up here
#LoadModule ssl_module modules/mod_ssl.so

# PHP 5.2.3
LoadModule php5_module "c:/php/php-5.2.3-Win32/php5apache2_2.dll"
PHPIniDir "C:/php/php-5.2.3-Win32"

AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

<Directory "C:/php/php-4.4.7-Win32">
    AllowOverride None
    Options None
    Order allow,deny
    Allow from all
</Directory>

# 'Main' server configuration
... etc

3) Save the httpd.conf file.

4) Now edit the httpd-vhosts.conf file.

5) The way this works is that ALL sites will run under PHP 5 module by default, unless you configure their Virtual Host entry to use PHP 4 instead. So let's take an existing Virtual Host and change it to use PHP 4:

<VirtualHost *:80>
    DocumentRoot D:/sandbox/public_html
    ServerName sandbox.dev
    ServerAlias www.sandbox.dev
    ErrorLog D:/sandbox/www_logs/error_log.txt
    CustomLog D:/sandbox/www_logs/access_log.txt common
    php_value error_log "D:/sandbox/php_error_log.txt"
    ScriptAlias /php/ "C:/php/php-4.4.7-Win32/"
    <Directory "D:/sandbox/public_html">
        AddHandler php-script .php
        Action php-script /php/php.exe
        AllowOverride None
        Options None
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

This is exactly the same as a typical Virtual Host entry except we've added 3 lines to it:

ScriptAlias /php/ "C:/php/php-4.4.7-Win32/"

To tell Apache to look in the PHP 4 folder for /php/ requests.

AddHandler php-script .php
Action php-script /php/php.exe

These two lines within the Directory section tell the site to use the PHP 4 CGI .exe file.

6) Stop and Start Apache and you should now find that the Virtual Host you configured above will use PHP 4.4.7 in CGI/FastCGI mode, while your other sites will use the PHP 5.2.3 Apache Module. Voila! No more switching required.

< Previous Index Next >

Need help? Post in the WAMP Guide Forum!

© Copyright 2007 - 2008 Richard Davey