Everyday computing made easier.
How to install PHP on IIS7
This post is broken up into 3 different Categories for a better reading experience.
I. How to install IIS7 and CGI on Windows 2008.
II. How to install and configure PHP on IIS7.
III. How to configure IIS7 to accept PHP requests.
I also recommend you purchase the following books if you wish to master IIS7 administration.
I. Install IIS7 and CGI.
1. Install IIS7 on Windows 2008 and be sure to add the CGI role.
2. If you’ve already installed IIS7 but not the CGI role then you’ll need to go into Server Manager -> Roles –>Web Server –> Add Role Services.

This will enable both the CGI and FastCGI services.
3. If you are a windows Windows Vista SP1 or higher user.
Add the CGI feature by going to Control Panel -> Programs and Features -> Turn Windows features on or off. This enables both the CGI and FastCGI services.
WARNING! AHTUNG! BHEMANIE! ADVERTENCIA! ALERTE!
BE SURE TO INSTALL THE UPDATE FOR FASTCGI MODULE!
The update for IIS 7.0 FastCGI module fixes several known compatibility issues with popular PHP applications. Install the update from one of the following locations:
- Update for Windows Server 2008
- Update for Windows Server 2008 x64 Edition
- Update for Windows Server 2008 for Itanium-based Systems
- Update for Windows Vista SP1
- Update for Windows Vista SP1 for x64 based Systems
II. Install and Configure PHP
- Download the latest non-thread safe zip package from here.
- Unpack the files to a directory of your choice (e.g. C:\PHP5) and rename the php.ini-development to php.ini.
- Open the php.ini file, then uncomment and modify settings as follows:
- Enable fastcgi.impersonate = 1.
FastCGI under IIS supports the ability to impersonate security tokens of the calling client. This allows IIS to define the security context that the request runs under. - Enable cgi.fix_pathinfo=1.
cgi.fix_pathinfo provides *real* PATH_INFO/PATH_TRANSLATED support for CGI. PHP’s previous behavior was to set PATH_TRANSLATED to SCRIPT_FILENAME, and to not care what PATH_INFO is. For more information on PATH_INFO, see the cgi specs. Setting this to 1 will cause PHP CGI to fix its paths to conform to the spec - Set cgi.force_redirect = 0.
- Set open_basedir to point to a folder or network path where the content of the web site(s) is located (ie- c:\domains or c:\inetpub).
- Set extension_dir to point to a location where PHP extensions reside. Typically, for PHP 5.2.X that would be set as extension_dir = “./ext”
- Enable the required PHP extension by un-commenting corresponding lines, for example:extension=php_mssql.dll
extension=php_mysql.dll
- Enable fastcgi.impersonate = 1.
- To test if the PHP installation is successful, run the following from the command line prompt:
C:\PHP>php –info
If PHP was installed correctly and all its dependencies are available on the machine, then this command will output the current PHP configuration information.
III. Configure IIS 7.0 to Handle PHP Requests
In order for IIS 7.0 to host PHP applications, it is necessary to add a handler mapping that tells IIS to pass all PHP specific requests to the PHP application framework via FastCGI protocol.
Using IIS Manager
1. Open IIS Manager and then select and open “Handler Mappings” at the server level:
2. Select the “Add Module Mapping” action
3. specify the configurations settings as listed on the below:
- Request path: *.php
- Module: FastCgiModule
- Executable: “C:\[Path to your PHP installation]\php-cgi.exe”
- Name: PHP via FastCGI
4. Click OK. A dialog box appears asking if you want to create a FastCGI application for this executable. Click Yes.
5. Test that the handler mapping works correctly by creating a phpinfo.php file in the C:\inetpub\wwwroot folder that contains the following code:
<?php phpinfo(); ?>
6. Open a browser and navigate to http://localhost/phpinfo.php.
If everything was setup correctly, then you will see the standard PHP information page:
| Print article | This entry was posted by caneja on October 16, 2009 at 1:30 pm, and is filed under IIS7. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |