Tips that may help you install PHP on Windows


Tips that may help you install PHP on Windows

My software environment:

Windows Server 2003 SP1


Apache 2.0.54

PHP 4.4.0

PHP 5.0.5



There are many instructions and tutorials on the web talking about the installation of PHP. Here is just another one. I prefer to manually unzip and configure, so I’m not talking about the Windows Installer case.

  • To install PHP as an Apache2 module,
    Suppose you have unzipped the PHP package to c:/php (later referred to as the main folder) keeping the directory structure unchanged. The PHP manual suggests that "
    In PHP 4, you should move all files located in the dll and sapi folders to the main folder (e.g. C:\php).", however I didn’t find it necessary for my software environment and needs. (explained later)


The first thing to do is to add a few lines in httpd.conf in order to a) tell Apache to load the php module. b) add the .php extension as an application type c) tell Apcache where php.ini is located.

For PHP4:



LoadModule php4_module "c:/php/sapi/php4apache2.dll"

AddType application/x-httpd-php .php


# configure the path to php.ini

PHPIniDir "c:/php/"



For PHP5:



# For PHP 5 do something like this:

LoadModule php5_module "c:/php/php5apache2.dll"

AddType application/x-httpd-php .php


# configure the path to php.ini

PHPIniDir "c:/php/"



I’ve heard someone saying that it’s essential to add the trailing slash. However my tests did not approve this.


Then make sure the php.ini is available. One quickest way is to copy php.ini-recommended located in the main folder as php.ini.


Now you have to make the php4ts.dll/php5ts.dll(located in the main folder) available. The manual introduces 3 ways. I’d choose to add the main folder to the PATH environment variable. You can alternatively copy the dll to the bin directory of Apache, but remember to update the dll when you upgrade php to a newer version.

The fact is that phpXts.dll is required when the server loads the ISAPI. If you put phpXts.dll and phpXapache2.dll in the same directory, you don’t need to even read the paragraph above. In PHP4, by default, php4ts.dll is in the main folder whereas php4apache2.dll is placed in main folder/sapi, so we have to do something to specify the location of php4ts.dll. However, in PHP5, php5ts.dll and php5apache2.dll are both placed under the main folder by default. When the server loads php5 ISPAI dll, it founds that php5ts.dll is required and looks for it in the current directory (we know, it’s there) and the loading succeeds.




  • Installing PHP5 on IIS6 and PHP4 on Apache2 at the same time

I’ve tried installing PHP5 on IIS6 and PHP4 on Apache2 at the same time.

It’s difficult to specify the correct location of php.ini respectively. Because both web server treat the PATH and PHPRC environment variables in similar way. But PHP5 and PHP4 have different php.ini files.

One way worked for me thought I don’t consider it a good way.

Use PHPIniDir to specify php.ini location for Apache.

Use PHPRC environment variable to specify php.ini location for IIS.

Don’t set the PATH environment variable, because I’ve experienced cases that IIS chose PATH prior to PHPRC. (The behavior depends on the order you set the two environment variables and whether you have restarted IIS or even the computer).

To make Apache work without setting the PATH environment, I copied php4ts.dll to the bin directory under the Apache installation root folder.


To make IIS reflect changes you made to the environment variables, only restarting the website configured in IIS is not enough. The PHP manual introduces a way to restart IIS "completely":

Run the two command in cmd:

NET STOP iisadmin



  • Can we run different versions of PHP using Apache2 at a same time?


Seems not possible if you have only one instance of Apache server. Because the LoadModule and AddType directive must appear in the server context (global).

2006-5-25, 10:03 Update

Yes, it is ok if you install php as cgi. But I haven’t explored much yet. Apache allows you to override PHPRC for a specific directory. You can run multiple versions of php under different directory. (You can also use apache virtual host.)

ScriptAlias /php5/ "C:/PHP5/"


<Directory "C:/Program Files/Apache Group/Apache/htdocs/php5-folder">
Action application/x-httpd-php /php5/php-cgi.exe
SetEnv PHPRC "C:/PHP5/"

See Upgrading to PHP 5 O’Reilly 2004 appendix c


  • Can we run different versions of PHP using IIS6 ate a same time?


Yes, we can. But there seems to be no way to specify php.ini locations for each IIS website respectively because there’s only one PHPRC environment variable. So all versions of PHP must share one php.ini, which is not desired in most cases.

This entry was posted in PHP Rocks. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s