http://www.emailcashpro.com

How to run PHP 4 and PHP 5 at the same time on Apache for Windows

A great article for running both PHH4 and PHP5 at the same time. :)

Article Source

"

Whilst the majority of web applications are hosted on Linux, most developers use Windows. Installing Apache, PHP, and MySQL on your Windows PC is recommended and has become much easier. However, few developers can test their pages in PHP 4 and PHP 5 on the same machine at the same time - but it is possible…

Environment overview

This article will not describe every step in detail, but it should give you enough information to create your own multi-PHP web development environment:

  1. We’ll define the domains http://test/ and http://test4/. Both will navigate to the same php files located in C:\WebPages\

  2. PHP 5 will be installed as an Apache SAPI module and will be used for pages in the domain http://test/.

  3. PHP 4 will be installed as a CGI binary. PHP files will be executed using PHP 4 by changing the domain to http://test4/ or accessing via port 81, e.g. http://test:81/

Note that the latest versions of PHP 5 run very slowly if you use the CGI binary. Defining it as a module solves this issue.

Installation ingredients

The freeware/open source software you’ll need is:

Both Apache and MySQL provide Windows installers, so just run them. All going well, you should then be able to navigate to http://localhost/ in your browser.

Extract PHP 4 to C:\php\php4 and PHP 5 to C:\php\php5. Follow the instructions for configuring your php.ini file, but ignore the Apache setup details for now - we’ll cover that below. One setting that may catch you out is extension_dir - for PHP 5 use:
extension_dir = "C:\php\php5\ext"

and for PHP 4 use:
extension_dir = "C:\php\php4\extensions\"

You can now uncomment any extensions you wish to use, e.g. extension=php_mysql.dll in PHP 5’s php.ini.

Windows system setup

Now all the files are in place, we’ll define the local domains test and test4. This is done by editing the hosts file, located in %WINDOWS%/system32/drivers/etc. Add the following lines:
127.0.0.1 test
127.0.0.1 test4

You can update your system using the command ‘nbtstat -R’, but you’ll need a reboot soon so don’t worry about it!

Now go to the Control Panel, open System, click the Advanced tab, and click Environment Variables. In the System variables section, click “Path” in the list followed by Edit. Add “;C:\php\php4;C:\php\php5″ to the end of the Variable value line.

Now reboot to make sure the settings are applied.

Configuring Apache

The Apache configuration file is normally located at %PROGRAMS%\Apache Group\Apache2\conf\httpd.conf You’ll need to locate and edit the following settings.

Set the server to listen on port 80 (the default) and port 81:
Listen 80
Listen 81

Ensure your root folder is set correctly (note the forward slash):
DocumentRoot "C:/WebPages"

Add php files to the directory index, e.g.
DirectoryIndex index.html index.php

Just before the Virtual Hosts section, define PHP 5 as a SAPI module:
# PHP5 module
LoadModule php5_module “c:/php/php5/php5apache2.dll”
AddType application/x-httpd-php .php
PHPIniDir “C:/php/php5″

Finally, we’ll define the localhost, test, and test4 virtual domain settings for ports 80 and 81. Where PHP 4 is required (test4 domain or port 81), it is defined as a CGI binary that will override the PHP5 module.

NameVirtualHost *:80
NameVirtualHost *:81

# localhost:80 - PHP5
<VirtualHost *:80>
DocumentRoot C:/WebPages
</VirtualHost>

# localhost:81 - PHP4
<VirtualHost *:81>

DocumentRoot C:/WebPages
ScriptAlias /php/ “c:/php/php4/”
Action application/x-httpd-php4 “/php/php.exe”
AddHandler application/x-httpd-php4 .php
</VirtualHost>

# test:80 - PHP5
<VirtualHost *:80>
ServerName test
DocumentRoot C:/WebPages
</VirtualHost>

# test:81 - PHP4
<VirtualHost *:81>
ServerName test
DocumentRoot C:/WebPages
ScriptAlias /php/ “c:/php/php4/”
Action application/x-httpd-php4 “/php/php.exe”
AddHandler application/x-httpd-php4 .php

</VirtualHost>

# test4:80 - PHP4
<VirtualHost *:80>
ServerName test4
DocumentRoot C:/WebPages
ScriptAlias /php/ “c:/php/php4/”
Action application/x-httpd-php4 “/php/php.exe”
AddHandler application/x-httpd-php4 .php
</VirtualHost>

# test4:81 - PHP4
<VirtualHost *:81>
ServerName test4
DocumentRoot C:/WebPages
ScriptAlias /php/ “c:/php/php4/”
Action application/x-httpd-php4 “/php/php.exe”
AddHandler application/x-httpd-php4 .php
</VirtualHost>

You’ll now need to restart Apache. It may be best to use “net stop apache2″ followed by “net start apache2″ on the command line. This will allow you to see any configuration error messages, but several other helpful tools are provided in the Apache program group.

Testing your environment

Create a new file phpinfo.php in C:\WebPages\. Edit the file and add the line:
<?php phpinfo(); ?>

Save it, then visit the following addresses in your browser:

  • http://test/phpinfo.php - should show PHP 5

  • http://test4/phpinfo.php - should show PHP 4

  • http://test:81/phpinfo.php - should show PHP 4
And that’s all there is to it!

Obviously, you can now define further virtual domains - perhaps one for every website you create. "

Post a Comment