How to Set up PHP on IIS7.5 Windows Server 2008 r2 with FastCGI

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)

  • 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.
  • Next lets head out to [url="http://php.net/downloads.php
  • and select the Windows {Version} binaries and source link.
  • 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.
  • 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.
  • After you have the zip file opened go ahead and select "Extract all files" near the top left corner of the window.
  • 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.
  • 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).
  • Then paste this file back in and rename it to be "php.ini"
  • 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
  • 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.
  • Next Open up the Internet Information Services (IIS) Manager.
  • Select the "Handler Mappings" for your server
  • Then click the "Add Module Mapping..." found in the top right corner of the Handler Mappings screen.
  • Then fill in the following information and click OK:
    Request path:

    *.php

    Module:

    FastCgiModule

    Executable (optional):

    {THE LOCATION OF YOUR PHP INSTALLATION}\php-cgi.exe

    Name:

    PHP via FastCGI

  • 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".
  • 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();?>
  • After you have added that file open a web browser on the server and go to [url="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.

你可能感兴趣的:(windows,server,2008)