How to Set up PHP on IIS7.5 with fastcgi

Goal: To allow .php files to run on a windows IIS 7.5 web server

Prerequisites: IIS 7.5 Webserver

With PHP being such a popular programming language for the web, it is important to understand how we can leverage our windows web server to run php. Below I will demonstrate how to install PHP 5.4 onto my brand new IIS7 web server. This server is running Windows 2008 r2 standard edition. A couple of disclaimers before I get started with the basic guide: You will need to adjust the paths in this guide suitable to your environment, I am using C: for my default website and S: (Secondary) drive for my program files (aka php installation). You will also need to make sure that you have the appropriate C++ runtime environment on your operating system. This is a fairly standard requirement so it is not included in this guide. Lastly, if you run into any problems or have question please feel free to reply to this thread or create your own and I will be more than happy to help you figure out what's going on (in my experience if you follow this guide and something isn't working it's a permission problem, or a php.ini configuration problem)

  1. The first step to making sure you can use PHP on your IIS server it to make sure you have CGI enabled. This can be done from the Server Manager under the Roles section.

    iis-php-11.png

  2. Next leats head out to http://php.net/downloads.php and select the Windows {Version} binaries and source link.

    iis-php-2.png

  3. Next make sure you download the "Non Thread Safe" zip file of the version you want. You may also notice that it says VC9 x86, this indicates that you will need the x86 version of the c++ 2008 package on your machine in order for php to run.

    iis-php-3.png

  4. You will then be presented with some sort of download menu, if your using a browser that supports it just go ahead and open the zip file.

    iis-php-4.png

  5. After you have the zip file opened go ahead and select "Extract all files" near the top left corner of the window.

    iis-php-5.png

  6. Now extract these files to wherever you want your php installation to be located. For me I have this on a secondary drive under Program Files. Following the extraction go ahead and open up that folder as we have some work to do in that directory before we're done.

    iis-php-6.png

  7. In your PHP installation directory copy your php.ini-production (or development depending on what kind of sites you are putting up on this box).

    iis-php-7.png

  8. Then paste this file back in and rename it to be "php.ini".

    iis-php-8.png

  9. In your php.ini file make sure you have the following set:

    open_basedir = {YOUR IIS WEBSITES PATH HERE}
    cgi.fix_pathinfo=1
    fastcgi.impersonate=1

    iis-php-9.png

  10. After this set up your extensions you wish to have enabled and configure the rest of your php.ini file to your liking. Save and close the file.

    iis-php-10.png

  11. Next Open up the Internet Information Services (IIS) Manager.

    iis-php-11.png

  12. Select teh "Handler Mappings" for your server

    iis-php-12.png

  13. Then click the "Add Module Mapping..." found in the top right corner of the Handler Mappings screen.

    iis-php-13.png

  14. Then fill in the following information and click OK: Request Path: *.php Module: FastCgiModule Executable (optional): [Enter the location of your php installation]\php-cgi.exe Name: PHP Via FastCGI

    iis-php-14.png

  15. After you click OK you will be prompted: "Do you want to create a FastCGI application for this executable? Click 'Yes' to add the entry to the FastCGI collection and to enable this executable to run as a FastCGI application." to which you should click "Yes".

    iis-php-15.png

  16. At this point you should have php running on your IIS server. To test, create a file called phpinfo.php in your default website directory (default is C:\inetpub\wwwroot) and put the following code in the file and save it.

    <?php
    phpinfo();

    iis-php-16.png

  17. After you have added that file open a web browser on the server and go to http://localhost/phpinfo.php and you should see your php information if php is working properly. If not revisit the steps above and try and find what you might have missed.
Loading Conversation