HOWTO: Install and Run PHP on IIS7, Part 2


A couple of months ago, I wrote a quick and dirty entry on how to install PHP on IIS7. The main purpose of that entry was to explain the details of what was going on as well as cookie-cutter instructions of one way to successfully install PHP on IIS7.


Well, the responses that I have received from that blog entry made me realize that I need to provide something a little more shrink-wapped which does a few more things other than just run the bare minimum… because I was seeing way too many broken custom modifications coming from mistaken assumptions about PHP or IIS7.


Here it is, V2. Just copy/paste the following into a .bat file, right-click run it as elevated Administrator on Vista, and follow the prompted instructions. You should have PHP extracted into a directory of your choice before-hand (I favor and default to %SYSTEMDRIVE%\Inetpub\PHP for many aforementioned reasons; in my examples, I chose “C:\Program Files\P H P” to show it working with long pathnames).


The batch script:



  • Works with PHP installed wherever, including pathnames with spaces. Just tell it where you installed PHP (sans double quotes and trailing backslash)
  • Gives choice of whether to use the CGI or ISAPI version of PHP. You do have to give the correct binary name (php5isapi.dll or php-cgi.exe, assuming PHP5), but there are checks for that
  • Gives warnings and errors if the directory/file does not exist, mismatched binary types, and additional steps you need to do to have a minimally functioning PHP

Now, I am no PHP expert, so I can only give instructions for how to get PHP configured and running on IIS7. Questions about all other PHP-related features (like PHP extensions, integration with mySQL, etc) and how to get them working really belong on a PHP support forum.


Sample Execution Results:



  • Setting up PHP5 installed at “C:\Program Files\P H P”, ISAPI version. Notice the defaults and verification of provided inputs.
David.Wang’s Sample PHP/IIS7 Configurator
Version: June 2006

—————————— Summary ——————————
PHP Binaries Dir : C:\Inetpub\PHP
PHP Binary Type : ISAPI
PHP Binary Name : php5isapi.dll
———————————————————————

Validating inputs…

ERROR: PHP Binary “C:\Inetpub\PHP\php5isapi.dll” does not exist!
Please first completely extract PHP to “C:\Inetpub\PHP”

Remember to tweak PHP.INI for security and functionality per php.net
Finished input validation.

Press 1 to EDIT choices, or ENTER to start IIS modifications:1

Press ENTER to accept [C:\Inetpub\PHP], or provide new value (folder path)
PHP Binaries Dir:C:\Program Files\P H P
Press ENTER to accept [ISAPI], or provide new value (CGI or ISAPI)
PHP Binary Type:
Press ENTER to accept [php5isapi.dll], or provide new value (filename)
PHP Binary Name:

David.Wang’s Sample PHP/IIS7 Configurator
Version: June 2006

—————————— Summary ——————————
PHP Binaries Dir : C:\Program Files\P H P
PHP Binary Type : ISAPI
PHP Binary Name : php5isapi.dll
———————————————————————

Validating inputs…

Remember to tweak PHP.INI for security and functionality per php.net
Finished input validation.

Press 1 to EDIT choices, or ENTER to start IIS modifications:

Starting IIS7 Configuration…

Copying “C:\Program Files\P H P\PHP.INI-Recommended” to PHP.INI…
Setting PHP Handler…
CONFIG object “system.webServer/handlers” changed
Adding and Enabling PHP in ISAPI/CGI Restriction List…
CONFIG object “system.webServer/security/isapiCgiRestriction” changed

Finished IIS7 Configuration.

Test installation using PHP file content of: <?php phpinfo();?>



  • Setting up PHP5 installed at “C:\Program Files\P H P”, CGI version. Notice the defaults and reminders as you change to CGI.
David.Wang’s Sample PHP/IIS7 Configurator
Version: June 2006

—————————— Summary ——————————
PHP Binaries Dir : C:\Inetpub\PHP
PHP Binary Type : ISAPI
PHP Binary Name : php5isapi.dll
———————————————————————

Validating inputs…

ERROR: PHP Binary “C:\Inetpub\PHP\php5isapi.dll” does not exist!
Please first completely extract PHP to “C:\Inetpub\PHP”

Remember to tweak PHP.INI for security and functionality per php.net
Finished input validation.

Press 1 to EDIT choices, or ENTER to start IIS modifications:1

Press ENTER to accept [C:\Inetpub\PHP], or provide new value (folder path)
PHP Binaries Dir:C:\Program Files\P H P
Press ENTER to accept [ISAPI], or provide new value (CGI or ISAPI)
PHP Binary Type:cgi
Press ENTER to accept [php5isapi.dll], or provide new value (filename)
PHP Binary Name:php-cgi.exe

David.Wang’s Sample PHP/IIS7 Configurator
Version: June 2006

—————————— Summary ——————————
PHP Binaries Dir : C:\Program Files\P H P
PHP Binary Type : cgi
PHP Binary Name : php-cgi.exe
———————————————————————

Validating inputs…

ERROR: PHP CGI requires modifying cgi.force_redirect to 0 in “C:\Program Files\P H P\PHP.INI”

Remember to tweak PHP.INI for security and functionality per php.net
Finished input validation.

Press 1 to EDIT choices, or ENTER to start IIS modifications:

Starting IIS7 Configuration…

Copying “C:\Program Files\P H P\PHP.INI-Recommended” to PHP.INI…
Setting PHP Handler…
CONFIG object “system.webServer/handlers” changed
Adding and Enabling PHP in ISAPI/CGI Restriction List…
CONFIG object “system.webServer/security/isapiCgiRestriction” changed

Finished IIS7 Configuration.

Test installation using PHP file content of: <?php phpinfo();?>


Enjoy.


//David

@IF ?%_ECHO%?==?? ECHO OFF

SETLOCAL
SET DIR_PHP_FROM=%SYSTEMDRIVE%\Inetpub\PHP
SET PHP_TYPE=ISAPI
SET PHP_MODULE=IsapiModule
SET PHP_BINARY=php5isapi.dll

:Menu
ECHO.
ECHO David.Wang’s Sample PHP/IIS7 Configurator
ECHO Version: June 2006
ECHO.
ECHO —————————— Summary ——————————
ECHO PHP Binaries Dir : %DIR_PHP_FROM%
ECHO PHP Binary Type : %PHP_TYPE%
ECHO PHP Binary Name : %PHP_BINARY%
ECHO ———————————————————————

REM
REM Do some basic validations
REM
ECHO.
ECHO Validating inputs…
IF /I ?%PHP_TYPE%? NEQ ?CGI? IF /I ?%PHP_TYPE%? NEQ ?ISAPI? ECHO.&ECHO ERROR: Binary Type MUST be either CGI or ISAPI
FOR %%I IN ( %PHP_BINARY% ) DO (
IF /I ?%PHP_TYPE%? EQU ?CGI? IF /I ?%%~xI? NEQ ?.exe? ECHO.&ECHO WARNING: Binary Type %PHP_TYPE% requires a CGI EXE binary
IF /I ?%PHP_TYPE%? EQU ?ISAPI? IF /I ?%%~xI? NEQ ?.dll? ECHO.&ECHO WARNING: Binary Type %PHP_TYPE% requires an ISAPI DLL binary
)
IF NOT EXIST “%DIR_PHP_FROM%\%PHP_BINARY%” (
ECHO.
ECHO ERROR: PHP Binary “%DIR_PHP_FROM%\%PHP_BINARY%” does not exist!
ECHO Please first completely extract PHP to “%DIR_PHP_FROM%”
)
IF /I ?%PHP_TYPE%? EQU ?CGI? SET PHP_MODULE=CgiModule
IF /I ?%PHP_TYPE%? EQU ?CGI? ECHO.&ECHO ERROR: PHP CGI requires modifying cgi.force_redirect to 0 in “%DIR_PHP_FROM%\PHP.INI”
IF /I ?%PHP_BINARY%? NEQ ?php5isapi.dll? IF /I ?%PHP_BINARY%? NEQ ?php-cgi.exe? ECHO.&ECHO WARNING: Unrecognized PHP binary %PHP_BINARY%
ECHO.
ECHO Remember to tweak PHP.INI for security and functionality per php.net
ECHO Finished input validation.
ECHO.

SET GO=
SET /P GO=Press 1 to EDIT choices, or ENTER to start IIS modifications:
IF ?%GO%? EQU ?? GOTO :Start

ECHO.
ECHO Press ENTER to accept [%DIR_PHP_FROM%], or provide new value (folder path)
SET /P DIR_PHP_FROM=PHP Binaries Dir:
ECHO Press ENTER to accept [%PHP_TYPE%], or provide new value (CGI or ISAPI)
SET /P PHP_TYPE=PHP Binary Type:
ECHO Press ENTER to accept [%PHP_BINARY%], or provide new value (filename)
SET /P PHP_BINARY=PHP Binary Name:

GOTO :Menu

:Start
REM
REM Start Configuration
REM
IF NOT EXIST “%DIR_PHP_FROM%\%PHP_BINARY%” (
ECHO.
ECHO ERROR: PHP Binary “%DIR_PHP_FROM%\%PHP_BINARY%” does not exist!
ECHO Please first completely extract PHP to “%DIR_PHP_FROM%”
GOTO :EOF
)

ECHO.
ECHO Starting IIS7 Configuration…
ECHO.
ECHO Copying “%DIR_PHP_FROM%\PHP.INI-Recommended” to PHP.INI…
COPY /Y “%DIR_PHP_FROM%\PHP.INI-Recommended” “%DIR_PHP_FROM%\PHP.INI” >NUL

PUSHD %SYSTEMROOT%\System32\inetsrv

ECHO Setting PHP Handler…
APPCMD SET CONFIG -section:handlers “-+[name=’PHP-%PHP_TYPE%’,path=’*.php’,verb=’GET,HEAD,POST’,modules=’%PHP_MODULE%’,scriptProcessor=’%DIR_PHP_FROM%\%PHP_BINARY%’,resourceType=’File’]”

ECHO Adding and Enabling PHP in ISAPI/CGI Restriction List…
APPCMD SET CONFIG -section:isapiCgiRestriction “-+[path=’%DIR_PHP_FROM%\%PHP_BINARY%’,allowed=’true’,groupId=’PHP’,description=’PHP’]”

POPD

ECHO.
ECHO Finished IIS7 Configuration.
ECHO.
ECHO Test installation using PHP file content of: ^<?php phpinfo();?^>

ENDLOCAL

Comments (51)

  1. thanks for posting! be patient with us 🙂

  2. Harris says:

    David,

    This is excellent, thank you!  Sadly, though, I must be the pest to ask if it is possible to come up with something similar for IIS6 since I do not have access to Vista/IIS7 and occassionally have to support PHP on W2k3.

    Any help or insight is greatly appreciated.

    Thanks,

    Harris

  3. David.Wang says:

    Harris – Sure. It is not hard to make a similar script for IIS6 (in fact, one just need to change two lines of code), and it should also work on IIS5.1, IIS5.0, and IIS4.0. Feel free to challenge yourself and make the change; no help/insight needed.

    It will require that you:

    1. Download and provide my LIST Manipulation script at:

    http://blogs.msdn.com/david.wang/archive/2004/12/02/273681.aspx

    2. Change the first APPCMD call to use my LIST Manipulation script on W3SVC/ScriptMaps to insert the PHP Application Mapping

    3. Change the second APPCMD call to use iisext.vbs to enable the right binary

    On IIS4, IIS5, and IIS5.1, iisext.vbs does not exist and #3 is not necessary so it will silently fail, but that’s ok. If you want to get fancy you can detect IIS’s major/minor version and behave accordingly.

    I may write a third and final blog entry sometime later to pull it all together with a multi-IIS-version installer, but please don’t wait for me; feel free to help yourself.

    //David

  4. David Wang says:

    A short while ago, I came out with a small script to properly configure PHP for IIS7. Sure enough, I…

  5. Daniel Alfaro says:

    Este script es fenomenal, te agradezco mucho por esto, ahora me puedo mover a Vista en mi ambiente de desarrollo con toda confianza!

  6. David.Wang says:

    Daniel – de nada. 🙂

    //David

  7. attila says:

    Hi David,

    could you write something about how to set up mysql with php and IIS7? Because i already installed them succesfully but can’t make them work on IIS7. Don’t you know any solution for this, too?

    Thanks a lot;

    Attila

  8. As far as I’m aware, the PHP 5.2.0 Windows installer doesn’t work with Vista [I’m assuming; haven’t actually…

  9. Joe says:

    Thanks a million on this.  I couldn’t get the PHP installer to work so I just d/l the binaries and did what you instructed and works like magic!

  10. stepanet says:

    Hi from Russian. i need help. IIS7 + PHP

    ERROR 503

    in russian

    Не удается найти точку входа RegisterModule в модуле библиотеки DLL C:PHPphp5isapi.dll.  Данные представляют собой код ошибки.

    in english

    I can’t find a’point of entrance RegisterModule in library module DLL C:PHPphp5isapi.dll

    Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event"&gt;

    – <System>

     <Provider Name="Microsoft-Windows-IIS-W3SVC-WP" Guid="{670080D9-742A-4187-8D16-41143D1290BD}" EventSourceName="W3SVC-WP" />

     <EventID Qualifiers="49152">2295</EventID>

     <Version>0</Version>

     <Level>2</Level>

     <Task>0</Task>

     <Opcode>0</Opcode>

     <Keywords>0x80000000000000</Keywords>

     <TimeCreated SystemTime="2007-04-11T04:51:06.000Z" />

     <EventRecordID>2967</EventRecordID>

     <Correlation />

     <Execution ProcessID="0" ThreadID="0" />

     <Channel>Application</Channel>

     <Computer>stepanet-PC</Computer>

     <Security />

     </System>

    – <EventData>

     <Data Name="ModuleDll">C:PHPphp5isapi.dll</Data>

     <Binary>7F000000</Binary>

     </EventData>

     </Event>

  11. Joel says:

    Ummm, when I run the .bat file, it closes itself after I get to the "IIS Modifications" part??? Help!

  12. Jason says:

    I ran the bat, and it configured everything but now I cant get html or php pages to load. I checked the configs and I cannot find anything wrong. This is really frustrating.

  13. Damian says:

    David,

    I had been struggling to get MySQL, PHP and IIS 7 working all day. However, you script has managed to resolve all my issues within minutes. Thanks for all your help.

  14. Carlos says:

    Good day,

    I have Vista Ultimate with IIS7 I downloaded the latest PHP package off their website and ran your script above. But I keep getting:

    Starting IIS7 Configuration…

    Copying "C:inetpubwwwrootphpPHP.INI-Recommended" to PHP.INI…

    Setting PHP Handler…

    ERROR ( message:New add object missing required attributes. Cannot add duplicate

    collection entry

    . )

    Adding and Enabling PHP in ISAPI/CGI Restriction List…

    ERROR ( message:New add object missing required attributes. Cannot add duplicate

    collection entry

    . )

    Finished IIS7 Configuration.

    The ISAPI filter can be seen in the handlers section of the IIS server and when I try to access a php site i get Service Unavailable error.

    I would appreciate the help

    Thanks

    Carlos

  15. David.Wang says:

    Carlos – it appears that you already ran some prior installation routine which added the handler for PHP and its Web Service Extension. You also say you have the ISAPI filter placed as a handler, which is improper configuration and will result in problems.

    I suggest that you clean install IIS7 and make sure ISAPI Extension, unzip PHP, and run my batch file again to install the PHP ISAPI Extension DLL as the handler. My batch file does not try to fix any IIS7 configuration problems to make PHP work, so it will only work if you clean install IIS7, unzip PHP, and run it once.

    //David

  16. yZ says:

    Hi,

    I have encouter the following error after setting teh handler and php.

    ———————————————————————————-

    HTTP Error 404.0 – Not Found

    Description: The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.

    Error Code: 0x80070002

    Notification: MapRequestHandler

    Module: IIS Web Core

    Requested URL: http://localhost:80/testing.php

    Physical Path: C:inetpubwwwroottesting.php

    Logon User: Anonymous

    Logon Method: Anonymous

    Handler: PHP

    ———————————————————————————-

    During my installation of IIS under Application Development Features, I have checked all the extensible options (.Net Extensibility, ASP, ASP.NET etc.) instead of just ISAPI Extensions.

    Any one can hep me?

  17. David.Wang says:

    yZ – this is a real 404 "file not found". Web server says that C:inetpubwwwroottesting.php does not exist.

    //David

  18. Ali Awais says:

    I tried your procedure, (additionaly: newly installed Vista Business, turn the windows feature, IIS7, on, with CGI module activated), extracted PHP 5.2.2 in C:PHP and ran your BAT file.

    Now it said everything was successful. No errors at all… But still my php server doesn’t works. Detailed error when the script is called is as below:

    Server Error in Application "Default Web Site"

    ——————————————————————————–

    HTTP Error 500.0 – Internal Server Error

    Description: The page cannot be displayed because an internal server error has occurred.

    Error Code: 0x800736b1

    Notification: ExecuteRequestHandler

    Module: CgiModule

    Requested URL: http://localhost:80/info.php

    Physical Path: C:inetpubwwwrootinfo.php

    Logon User: Anonymous

    Logon Method: Anonymous

    Handler: PHP-CGI

    ——————————————————————————–

    Previously, I did the same thing in Vista Ultimate with IIS7, but I got the same error…

    Can you please suggest me a solution to this problem.

  19. David.Wang says:

    Ali – the error code suggests that something is wrong with either the PHP script or PHP configuration itself. IIS has launched PHP to process C:inetpubwwwrootinfo.php, and PHP failed. You will have to look at the installation correctness of PHP.

    If I remember correctly, there are several additional steps that one needs to do to get the CGI version of PHP to work, outside of just extracting PHP files, and my batch file suggests them to you. If they are insufficient, I suggest you consult PHP-related support forums to determine how to get PHP functional because I cannot support PHP’s internal configuration, only its configuration related to IIS7.

    //David

  20. Markoz says:

    This script is great !!! aftre small modifications can be used for perl module installations as well

    @IF ?%_ECHO%?==?? ECHO OFF

    SETLOCAL

    SET DIR_PERL_FROM=%SYSTEMDRIVE%PERLbin

    SET PERL_TYPE=ISAPI

    SET PERL_MODULE=IsapiModule

    SET PERL_BINARY=perlis.dll

    :Menu

    ECHO.

    ECHO David.Wang’s Sample PERL/IIS7 Configurator

    ECHO Version: June 2006

    ECHO.

    ECHO —————————— Summary ——————————

    ECHO PERL Binaries Dir : %DIR_PERL_FROM%

    ECHO PERL Binary Type  : %PERL_TYPE%

    ECHO PERL Binary Name  : %PERL_BINARY%

    ECHO ———————————————————————

    REM

    REM Do some basic validations

    REM

    ECHO.

    ECHO Validating inputs…

    IF /I ?%PERL_TYPE%? NEQ ?CGI? IF /I ?%PERL_TYPE%? NEQ ?ISAPI? ECHO.&ECHO ERROR: Binary Type MUST be either CGI or ISAPI

    FOR %%I IN ( %PERL_BINARY% ) DO (

       IF /I ?%PERL_TYPE%? EQU ?CGI? IF /I ?%%~xI? NEQ ?.exe? ECHO.&ECHO WARNING: Binary Type %PERL_TYPE% requires a CGI EXE binary

       IF /I ?%PERL_TYPE%? EQU ?ISAPI? IF /I ?%%~xI? NEQ ?.dll? ECHO.&ECHO WARNING: Binary Type %PERL_TYPE% requires an ISAPI DLL binary

    )

    IF NOT EXIST "%DIR_PERL_FROM%%PERL_BINARY%" (

       ECHO.

       ECHO ERROR: PERL Binary "%DIR_PERL_FROM%%PERL_BINARY%" does not exist!

       ECHO Please first completely extract PERL to "%DIR_PERL_FROM%"

    )

    IF /I ?%PERL_TYPE%? EQU ?CGI? SET PERL_MODULE=CgiModule

    IF /I ?%PERL_TYPE%? EQU ?CGI? ECHO.&ECHO ERROR: PERL CGI requires modifying cgi.force_redirect to 0 in "%DIR_PERL_FROM%PERL.INI"

    IF /I ?%PERL_BINARY%? NEQ ?perlis.dll? IF /I ?%PERL_BINARY%? NEQ ?php-cgi.exe? ECHO.&ECHO WARNING: Unrecognized PERL binary %PERL_BINARY%

    ECHO.

    ECHO Finished input validation.

    ECHO.

    SET GO=

    SET /P GO=Press 1 to EDIT choices, or ENTER to start IIS modifications:

    IF ?%GO%? EQU ?? GOTO :Start

    ECHO.

    ECHO Press ENTER to accept [%DIR_PERL_FROM%], or provide new value (folder path)

    SET /P DIR_PERL_FROM=PERL Binaries Dir:

    ECHO Press ENTER to accept [%PERL_TYPE%], or provide new value (CGI or ISAPI)

    SET /P PERL_TYPE=PERL Binary Type:

    ECHO Press ENTER to accept [%PERL_BINARY%], or provide new value (filename)

    SET /P PERL_BINARY=PERL Binary Name:

    GOTO :Menu

    :Start

    REM

    REM Start Configuration

    REM

    IF NOT EXIST "%DIR_PERL_FROM%%PERL_BINARY%" (

       ECHO.

       ECHO ERROR: PERL Binary "%DIR_PERL_FROM%%PERL_BINARY%" does not exist!

       ECHO Please first completely extract PERL to "%DIR_PERL_FROM%"

       GOTO :EOF

    )

    ECHO.

    ECHO Starting IIS7 Configuration…

    ECHO.

    PUSHD %SYSTEMROOT%System32inetsrv

    ECHO Setting PERL Handler…

    APPCMD SET CONFIG -section:handlers "-+[name=’PERL-%PERL_TYPE%’,path=’*.pl’,verb=’GET,HEAD,POST’,modules=’%PERL_MODULE%’,scriptProcessor=’%DIR_PERL_FROM%%PERL_BINARY%’,resourceType=’File’]"

    ECHO Adding and Enabling PERL in ISAPI/CGI Restriction List…

    APPCMD SET CONFIG -section:isapiCgiRestriction "-+[path=’%DIR_PERL_FROM%%PERL_BINARY%’,allowed=’true’,groupId=’PERL’,description=’PERL’]"

    POPD

    ECHO.

    ECHO Finished IIS7 Configuration.

    ECHO.

    ECHO Test installation using PERL file

    ENDLOCAL

    Greetings

    Marek Kozniewski

    ITAC

  21. Omi Joshi says:

    Thanx David Wang a ton for helping me to install PHP on IIS7 in a few minutes. I was trying to install PHP on IIS7 for last one and half day and you made is so easy for me. Thanx again

  22. Rick says:

    After running the script, I get the HTTP Error 500.0 error – Handler "PHP" has a bad module "IsapiModule" in its module list.  Could someone please give me detailed instructions for fixing this?

  23. Rick says:

    I figured out my problem with the 500.0 error.  Apparently IIS7 defaults to none of the ISAPI or CGI scripting features.  You have to turn on these features.  Go to Control Panel->Programs and Features.  Click on "Turn Windows features on or off".  Under Internet Information Services->World Wide Web Services->Application Development Features, check the needed boxes.  I just checked them all.  This fixed my problem.

  24. progstone says:

    I have installed php as isapy modult.

    All feautures all wokr,but i got problem with fopen function.

    How make access write for site folders in IIS7(Vista).

    Thanks.

  25. progstone says:

    It too simply.I’m sorry.

    Just make access for IIS_IUSRS for folder in inetpub.

  26. Yves Sucaet says:

    Does anybody know how to configure Xitami/PHP on Windows Vista? After editing the xitami.cfg file and trying a sample page, all I’m getting is a Windows dialog box with error message saying "CGI/FastCGI has stopped working: A problem caused the program to stop working completely. Windows will close the program and notify you if a solution is available". Yeah, right!

    Anyway, I’m expecting this has something to do with execution permissions and/or administrator rights. Does anybody have experience with this?

    I realize this page is about IIS/PHP, but it’s the closest I found on Vista/PHP-related problems.

    Much obliged,

    yves at iastate dot edu

  27. fahad says:

    I have used the BAT file to configure IIS7 with PHP 5 as CGI. I am getting following error:

    HTTP Error 502.2 – Bad Gateway

  28. Youssef says:

    I am on Vista, has anyone figured out "HTTP Error 502.2 – Bad Gateway" error?

  29. John says:

    answer to:

    "bad module ‘IsapiModule’ in its module list"

    Read the anwer already stated above:

    # re: HOWTO: Install and Run PHP on IIS7, Part 2

    Friday, August 24, 2007 4:58 PM by Rick

    I figured out my problem with the 500.0 error.  Apparently IIS7 defaults to none of the ISAPI or CGI scripting features.  You have to turn on these features.  Go to Control Panel->Programs and Features.  Click on "Turn Windows features on or off".  Under Internet Information Services->World Wide Web Services->Application Development Features, check the needed boxes.  I just checked them all.  This fixed my problem

  30. Don Baechtel says:

    I ran you script on Win Server 2008 with IIS 7 and PHP installed and it seemed to run OK. I tried to test it running a php file with the following contents in IE7. The page totle comes up but the rest of the page is balnk. How do I test it? Do I have to change settings of IE7 on WS2008 to see more?

    <html>

    <head>

    <title> PHP Test Script </title>

    </head>

    <body>

    <?php

    phpinfo( );

    ?>

    </body>

    </html>

  31. Martin says:

    Hi Wang!

    Did everything (I hope) you said. I get 503s, service unavailable  with the associated log entry (roughly translated): Cannot find registermodule entry point for module c:inetpubphpphp5isapi.dll. Error code is in the data field.

    Martin

  32. Nantech1 says:

    David:

    I ran your routine in my Vista Ultimate after a clean (re)install of IIS7 and the BAT file ends with no feedback. When I try to run a PHP file in a browser it opens up my Dreamweaver, since that was the default app for PHP before. This leads me to think that that IIS was not fully configured. What can I send you to help you diagnose?

    Thanks.

    – Nathan

  33. David.Wang says:

    Martin – you did not do what I have said. You configured PHP5ISAPI.DLL as a <globalModule> so the 503 is by-design due to misconfiguration. You cannot just configure an ISAPI DLL to be an IIS Module DLL – it does not work that way.

    Please follow the blog entry exactly.

    //David.

  34. David.Wang says:

    Nantech1 – The batch file is interactive and requires user input, so I am pretty certain you did not run configuration correctly. Since it needs to edit applicationHost.config, the batch file must run with elevated administrator privileges.

    If you try to run a PHP file in the browser and it opens up Dreamweaver, it means that you have downloaded PHP file from IIS, which is another misconfiguration. PHP files are not downloadable by default

    As I stated in the blog entry – my directions start from a clean installation of IIS7 with no special configurations. It will not correct any misconfigurations you may have already made.

    I am sorry, but I am only one person and simply do not have the capacity to support diagnosing anyone’s configuration, even if you can send it to me. You really need to find support from Open Source groups for PHP since this is their "responsibility." Remember, Open Source really means you take responsibility for your own support.

    //David

  35. Rob says:

    Well all I can say is THANK YOU….. great bat file….. followed your steps and hey presto…

    now for mysql

  36. Martin says:

    Hi again David!

    Please come down to my level. I didn’t do any of that, I just copied files and ran a script. Tell me what to type.

    Martin

  37. David.Wang says:

    Martin – I’m sorry, but I already told you exactly what to type, and you could not follow those instructions.

    Based on the error you disclosed earlier, I *know* you did not follow my instructions and "just copied files and ran a script", so how can I believe this time will be any different?

    Please show me you can follow instructions by doing what Rob did right before you and get PHP working.

    //David

  38. Martin says:

    THANK YOU… great script… presto…

    So much for, Rob. Tell me what I should do.

    You’re condescending me because your instructions are so easy.

    For the same reason I’m sure I’ve followed them.

  39. Sally says:

    Thanks for the script , however, I keep getting this error when I run the file :

    Setting PHP Handler…

    ERROR message: New add object missing required attributes. Cannot add duplicate collection entry

    Adding and enabling php in iSAPI CGI restriction list…

    ERROR message: new add object missing required attributes. Cannot add duplicate collection entry

    —————–

    what does that mean?

  40. dev loy says:

    Hi David,

    Excellant work, bunch of thanx. I have Vista Ultimate with SP1 and IIS 7.0 of course. I tried couple of methods to install and configure PHP.

    First I downloaded the non-threaded safe binaries for 5.2 PHP.

    Then did manual setting as described in another blog using FastCGI.

    I was getting 400 error for a simple PHP file with text in it.

    Then I ran your script, and it gave me the following output:

    Press 1 to EDIT choices, or ENTER to start IIS modifications:1

    Press ENTER to accept [C:InetpubPHP], or provide new value (folder path)

    PHP Binaries Dir:C:PHP

    Press ENTER to accept [ISAPI], or provide new value (CGI or ISAPI)

    PHP Binary Type:

    Press ENTER to accept [php5isapi.dll], or provide new value (filename)

    PHP Binary Name:php5.dll

    David.Wang’s Sample PHP/IIS7 Configurator

    Version: June 2006

    —————————— Summary ——————————

    PHP Binaries Dir : C:PHP

    PHP Binary Type  : ISAPI

    PHP Binary Name  : php5.dll

    ———————————————————————

    Validating inputs…

    WARNING: Unrecognized PHP binary php5.dll

    Remember to tweak PHP.INI for security and functionality per php.net

    Finished input validation.

    Press 1 to EDIT choices, or ENTER to start IIS modifications:

    Starting IIS7 Configuration…

    Copying "C:PHPPHP.INI-Recommended" to PHP.INI…

    Setting PHP Handler…

    Applied configuration changes to section "system.webServer/handlers" for "MACHIN

    E/WEBROOT/APPHOST" at configuration commit path "MACHINE/WEBROOT/APPHOST"

    Adding and Enabling PHP in ISAPI/CGI Restriction List…

    ERROR ( message:New add object missing required attributes. Cannot add duplicate

    collection entry of type ‘add’ with unique key attribute ‘path’ set to ‘C:PHP

    php5.dll’

    . )

    Finished IIS7 Configuration.

    Test installation using PHP file content of:  <?php phpinfo();?>

    I know I have "php5.dll" in my setting as I do not see php5isapi.dll in the C:PHP folder. I started getting 500 Error.

    I checked in my installed features I have all of the Web Development things CGI, ISAPI checked.

    I also downloaded the MSI and ran its setup and then ran your batch file again. I am still getting the 500 Server Error. Not sure whats missing here.

    Thank you once again.

  41. David.Wang says:

    dev loy – Unfortunately, the script only works if you start from a clean install of IIS7 with all necessary features, and known location of PHP files.

    The script only does what is correct to setup PHP. It doesn’t fix what is incorrect.

    Thus, using it after you run some other setup process will not be helpful. The script isn’t going to fix bad configuration and make everything magically work.

    Without giving me your applicationHost.config file or a FREB trace of the request with an error, there is no way to tell what is missing or misconfigured.

    //David

  42. Will says:

    Thank you for this. I struggled with this for three days, following a lot of wrong advice and wasting a lot of time.

  43. Fred McGinnis says:

    I also receive this error msg when attempting to install PHP using Wang batch file:

    message:New add object missing required attributes. Cannot add duplicate collection entry

    I have repeatedly reinstalled IIS7 and ISAPI extensions & filters are checked.  Please help.

  44. Fred McGinnis says:

    In order to get PHP running under IIS on Vista Home Premium, it was necessary to uncheck the ISAPI

    filters AND the ASP.NET boxes.  Whether it is ASP.NET or filters that were causing the problem, I haven’t a clue but you can’t uncheck one without unchecking the other so it is a moot point.

  45. David.Wang says:

    Fred – That sounds like a problem specific to your installation. The installation state of ISAPI Filter and ASP.Net are not related to PHP because it does not use any of those modules.

    My suspicion is that you (or some external program) mis-installed some ISAPI Filter on IIS7. That mis-instnallation will prevent anything else from working, not just PHP, so disabling ISAPI Filter turns off that misconfiguration and thus allows whath the batch file did to install IIS7 function.

    This batch file only works the first time it runs. As stated at the beginning, I am providing illustration of how to correctly configure PHP to run — NOT fix any setup and make PHP run successfully. The latter is beyond the scope of this blog.

    //David

  46. John C says:

    Wonderful to find the help you need. Thank you.

    One issue: the PHP script was not being interpreted it was just appearing in the output.

    I went back to the previous blog and found the the user permissions to the PHP location were not set for IIS_IUSRS – setting this fixed it.

    Thank you again.

  47. Guncha says:

    Hi David,

    I have configured the IIS 7.0 with the .bat script provided by you. My PHP and MySQL server are already installed. When I try to open the test.php file containing the phpinfo() function, the cursor keeps rotating and no error or page is displayed.

    Yesterday, I was able to open my URL and work on my URL without any issues on the same setup. But today it is not working again.

    Please guide me in resolving this issue.

    Regards,

    Guncha

  48. sinbadkan says:

    Hi David ,,

    IIS is working great with php5isapi  but when using zendcfg  every thing stop working >>  

    How can we resolve it

    Best Regards

  49. David.Wang says:

    sinbadkan – please contact the support personel for zendcfg regarding your question.

    //David

  50. ishu says:

    where is the .bat file content ? i can't find that please help