C.3 Windows

If you're running Windows, it's not easy to compile PHP, and you're probably already using PHP 4 as a CGI. Here's how to integrate a precompiled version of PHP 5 into an existing Apache setup:

  1. Download and install a precompiled Windows zip package.

  2. Configure your web server to handle PHP 5.

  3. Set an alternative php.ini location.

If you're using another web server, you will need to modify the configuration directions.

The first step is downloading and unzipping PHP 5. You can download Windows zip packages from http://www.php.net/downloads.php. (Be sure to grab the "zip" package instead of the installer.)

After you unzip the package, move it to a directory that is similar to your existing PHP 4 installation. On many systems, PHP 4 is at C:/PHP/, so these instructions place PHP 5 in C:/PHP5/.

Copy php.ini-recommended to php.ini and keep it in C:/PHP5/. Your pre-existing php.ini file is already located in someplace like C:/WINNT/, but you're not ready to overwrite it yet. Make whatever server-specific customizations you need to the new php.ini file.

Now you need to modify your web server configuration file to handle PHP 5. If you're running PHP 4 as a CGI, you should already have these three lines:

ScriptAlias /php/ "C:/PHP/"

Action application/x-httpd-php /php/php.exe

AddType application/x-httpd-php .php

This makes the file located at /php/php.exe under the document root execute files ending in .php. The ScriptAlias directive links this location to C:/PHP/php.exe on your filesystem.

Supplement this with one additional line to create another ScriptAlias, this time for PHP 5:

ScriptAlias /php5/ "C:/PHP5/"

This entry lets you hand off PHP files to the PHP 5 CGI. If you've placed PHP 5 in a different location, change C:/PHP5/ accordingly.

Now you're all set to override Apache to make PHP 5 process the files instead of PHP 4. Like the earlier examples in Section C.2, you can do this on either a directory-specific level or a virtual-host level. For example, for a directory:

<Directory "C:/Program Files/Apache Group/Apache/htdocs/php5-folder">

    Action application/x-httpd-php /php5/php-cgi.exe

    SetEnv PHPRC "C:/PHP5/"


The Action directive tells Apache to map PHP files to /php5/php-cgi.exe. The directory name, /php5/, is the new ScriptAlias location, and php-cgi.exe is the new name for the PHP 5 CGI binary. The unadorned php.exe is now used by the command-line version of PHP.

There's still the job of making PHP 5 use the correct php.ini file. PHP checks a variety of locations by default, which is bad because that's where your PHP 4 php.ini is stored. Because you used a prebuilt package, you couldn't alter this path during the configuration process.

Fortunately, you can still control where PHP searches for its php.ini file. When you set the PHPRC environment variable, PHP looks inside that directory for a php.ini file. Earlier, you created a configuration file in C:/PHP5/, so that's where you point PHPRC. You cannot specify a filename for PHPRC, only a directory.

This setup works with all the other configuration examples listed earlier in this appendix. You simply need to place the two lines just shown inside whatever Apache directive or httpd.conf file you want.