I’ve run PHP with Microsoft Internet Information Services (IIS) before (running on a Windows XP laptop) and I seem to remember the installation being quite straightforward. Even so, tonight I was installing PHP 5.2.6 with IIS 6 (on Windows Server 2003 R2 Enterprise x64 Edition) and I ran across a few issues. This post describes what was involved:
- Firstly, PHP can be installed in CGI, FastCGI or ISAPI mode. I used ISAPI.
- Secondly, there is anecdotal evidence that the Windows Installer version is problematic – for that reason you may prefer to use the ZIP file and perform a manual installation (as I did), following the instructions on the IIS Admin blog, which were:
- Extract the files to a location of your choice (I used C:\PHP to keep it simple but C:\Program Files (x86)\PHP would be better).
- Rename php.ini-recommended to php.ini.
- Edit the
extension_dir
line in php.ini to readextension_dir = C:\phpinstallationfolder\ext
. - Add the PHP installation folder to the
%path%
system variable (e.g. append;C:\PHP
to the existing path). - Create a web service extension for PHP using
cscript iisext.vbs /AddFile c:\phpinstallationfolder\php5isapi.dll 1 PHPISAPI 1 “PHP ISAPIâ€
. The new extension should show in IIS Manager with a status of Allowed. - Create an application extension mapping for .php files. Following the advice on the IIS Admin blog article that I referenced previously will remove all other mappings so I used the IIS Manager MMC instead (Default Web Site Properties, Home Directory, Configuration to add a mapping to the executable at
c:\phpinstallationfolder\php5isapi.dll
using extension.php
for all verbs). - Create a test file called phpinfo.php containing
<?php phpinfo(); ?>
. - Use a web browser to navigate to http://servername/phpinfo.php and the PHP information page should be displayed.
- If you are running on 64-bit Windows there are some extra steps in order to avoid an HTTP 500 Internal server error or the message %1 is not a valid Win32 application. It seems that this is caused by trying to load a 32-bit application (in this case PHP) inside a 64-bit worker process (as described in Microsoft knowledge base article 895976). To resolve this issue, enter
cscript adsutil.vbs SET W3SVC/AppPools/Enable32bitAppOnWin64 1
.adsutil.vbs
is one of the scripts installed into the wwwroot\AdminScripts folder but if you have removed it to secure the server (as I had), then it may be temporarily copied back to the server from another IIS installation. - To ensure that PHPinfo reflects the correct location of the php.ini file, create an environment variable called PHPRC referring to c:\phpinstallationfolder and restart the server or, alternatively, set the appropriate registry keys (although neither option seemed to have any effect for me).