Introduction
This is the sixth article of a series of blog post called the WIMPinator Chronicles that describe how to setup a PHP development environment for Windows 7 and IIS 7.5.
So far we covered how to install a Wordpress blog and all its dependencies using the WPI (Web Platform Installer). Then we added additional features and extensions to the PHP deployment on Windows for IIS. I explained how to get PEAR setup and how to download and deploy the PHPUnit unit testing framework using PEAR. The last two posts described how to install Eclipse PDT and make it work with Subversion source control using Subclipse. There is one big piece missing so far and this is the testing of your PHP project on your IIS test web server. The next two blog posts will describe how to create an IIS 7.5 Fast CGI web site from scratch and how to use ANT build tasks to deploy your PHP project from Eclipse to your IIS test server during a custom build step.
In this part I am going to first explain how to create an IIS 7.5 Fast CGI PHP web site on IIS 7.5 from scratch.
The Series
- Getting a Wordpress blog installed in a jiffy on Windows 7 using the Web Platform Installer
- Adding additional features to PHP
- Installing PEAR and PHPUnit
- Installing Eclipse PDT
- Configuring Eclipse PDT to work with Subversion source control
- Creating a new IIS 7.5 fast CGI web site
- Configuring Eclipse to work with Ant build tasks
- Setting up XDebug with Eclipse and IIS 7.5
- Setting up the Zend Debugger with Eclipse and IIS 7.5
- Configuring Ruby and Watir
- Moving a Wordpress blog from GoDaddy shared hosting to my local debugging system.
- NEW: Setting up the CodeIgnitor MVC framework with PDT and IIS 7.5
- NEW: Configuring IIS 7.5 Rewrite rules to exclude index.php from the URL
- NEW: Configuring SSL on IIS 7.5
References
This blog post is based on, sometimes out-of-date, articles that I found on the InterWeb. Here are the links for these:
http://learn.iis.net/page.aspx/246/using-fastcgi-to-host-php-applications-on-iis-70/
http://learn.iis.net/page.aspx/728/best-practices-for-php-on-the-microsoft-web-platform/
Creating a new web application
First open Internet Information Services (IIS) Manager. On Windows 7 just run Start and enter IIS. You should see something like this:
Figure 1: Open IIS Manager. Start –> Run –> IIS
Once IIS Manager is open connect to your local web server.
Figure 2: Connect to your local web server
Browse to your Default Web site node in your web sites connections tree on the left.
Figure 3: Select the Default Web Site
Using Explorer create a new folder that will be the root of your new web application. I created the folder under c:\inetpub\wwwroot. I called it CIM225.
Figure 4: Create new folder
Back in the IIS Manager right mouse click and select the Add Application… menu option.
Figure 5: Add Application…
This will open the Add Application dialog. Provide the Alias name of the application and the physical path. This is the folder that we just created.
Figure 6: Configure the path and the alias name of the new application
The new web application has been added to the Default Web Site.
Figure 7: CIM225 is a new web application
Enabling FastCGI
If PHP has been installed on Windows 7 using the Web Platform Installer, then PHP and IIS should be configured correctly out of the box for fast CGI. In any case I recommend to verify the settings. Here is how you do it.
First make sure that all required IIS modules are installed. Go do the Control Panel and click on the Programs node.
Figure 8: Open the Control Panel and then the Programs page
Then click on “Turn Windows features on or off” link. Now navigate to the IIS Settings->World Wide Web Services node and verify that CGI is installed.
Figure 9: Navigate to the IIS Settings and verify that CGI is installed
Now verify the configuration of the Handler Mappings in IIS to make sure that the *.php file extension is handled using FastCGI. Double click the Handler Mappings icon in the IIS Manager.
Figure 10: Double click the Handler Mappings Icon
In the Handler Mappings list find the PHP_via_FastCGI entry. If it is already there compare its settings with the ones that follow. If you can’t find it, then add it. Use the provided values below.
Figure 11: Verify the PHP_via_FastCGI entry for *.php
Verify the settings in the Edit Module Mapping dialog.
Figure 12: Verify the settings in the Edit Module Mapping dialog
The values must be:
Request path: *.php
Module: FastCgiModule
Executable: "C:\[Path to your PHP installation]\php-cgi.exe"
Name: PHP via FastCGI
Editing the PHP.INI file
Now its time to verify your php.ini file. Open the global php.ini file and verify the following configuration:
Note: Before you can change the php.ini file you must stop IIS. Run a command prompt as Administrator and stop IIS with the iisreset /stop command. You also might have to run the editor like notepad or notepad2 as Administrator in order to save the changes back to the document. A normal user normally doesn’t have access to the PHP folder. Don’t forget to enable IIS again later using iisreset /start.

Figure 13. Stop IIS as Administrator
In the PHP.ini file search for the following line and uncomment it, if necessary:
Set cgi.force_redirect = 0.

Figure 14: Before
Figure 15: After
Set 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.
Figure 16: Before
Figure 17: After
Set 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
Figure 18: Before
Figure 19: After
Set open_basedir to point to a folder or network path where the content of the web site(s) is located.

Figure 20: Use this setting on a production server to limit file access
This settings doesn’t seem to make sense on my dev machine, but should be used on a production server.
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"
Figure 21: Set the extension directory
Enable the required PHP extension by un-commenting corresponding lines, for example:
extension=php_mssql.dll
extension=php_mysql.dll
Figure 22: Enable necessary extensions
Now we are done with the php.ini configuration that is specific to running PHP as FastCGI under IIS 7.5. Next we look at the file access security settings.
Setting the Windows 7 file access permissions
The last important thing here is to assign the correct permissions to the web application folder. By default on Windows 7 the users don’t have write permissions for the application folder. In the next blog post of this series we are going to copy the current php project from the local Eclipse workspace straight into the root folder of the web application that we just created. For this we need write permissions for the user the Eclipse build runs under. In my case this user is the desktop user.
Here is how you do it:
Select the application folder CIM225 and right mouse click and select Properties. Then go to the Security tab.
Figure 23: Go to the Security tab in the web application folder properties
Press the Edit… button.
Figure 24: Edit the file access permissions
Then push Add and enter the user that Eclipse runs under. In my case it is the logged in user.
Figure 25: Add the Eclipse “Build” user
Then give this user Full Control permissions by clicking the Allow Full Control check box.
Figure 26: Full control to the web application folder
Testing the web application settings
Now let’s verify that everything is configured correctly.
After turning IIS back on run php –info in the command prompt and re-direct the output into a file. Look in the file for any errors.
Figure 27: Run php -info
In addition use a php-info.php file that calls phpinfo() function to return a similar result as nicely formatted html when requested by a browser.
Test that the handler mapping works correctly by creating a phpinfo.php file and copying it into the C:\inetpub\wwwroot folder and/or in your application folder. The PHP file contains the following code:
<?php phpinfo(); ?>
Figure 28: Create a phpinfo.php file and copy it into the default sites root folder
Open a browser and navigate to http://localhost/phpinfo.php. If everything was setup correctly, then you will see the standard PHP information page:
Figure 29: PHPInfo() requested from Default Website root.
Figure 30: PHPInfo() requested from web application root
Ausblick
Now we are setup for the next few blog posts that are all about testing and debugging the Eclipse PDT PHP project using Ant and debug extensions.
Stay tuned!