Run PHP with FastCGI in IIS 7.x

Source: Internet
Author: User
Tags php website

As a matter of fact, since Microsoft provided FastCGI support, there has been a detailed tutorial on how to configure FastCGI support for various versions of IIS and how to run php using FastCGI on the official site of IIS, so as early as IIS 7.0 just appeared, Microsoft has provided a more optimized way to run php on IIS-FastCGI. But until IIS 7.5 appears with Windows 7, there are also a lot of "prawns" on the Internet that teach cainiao how to configure ISAPI support in IIS 7.x (or even the method of copying files to the system directory not recommended in the PHP Manual) to support PHP. This article describes how to enable FastCGI in iis7.x and configure PHP.

My configuration environment is Windows 7x64 + IIS 7.5, but the content in this article should be completely common in Windows 7.x, because FastCGI has become a built-in component since IIS 7.0. For earlier versions, FastCGI support needs to be installed, and the configuration is slightly different.

Part I. Enable FastCGI support in IIS 7.x

Open in sequenceControl Panel |ProgramAnd components | enable or disable the WINDOWS function, The English version of the corresponding operation isControl Panel | programs and features | turn windows features on or OFF. Then enable FastCGI as shown in the following figure (check CGI to enable both CGI and FastCGI support ). You should select other items based on your needs. I checked the items to highlight them.

If it is iis7.0, Microsoft has released a series of upgrade patches to fix some of the known issues of the built-in FastCGI module. You can download the corresponding patches based on your system:

  • Update for Windows Server 2008
  • Update for Windows Server 2008x64 Edition
  • Update for Windows Server 2008 for itanium-based systems
  • Update for Windows Vista SP1
  • Update for Windows Vista SP1 for x64 based systems
    Part II. install and configure PHP

    Microsoft officialArticleWe recommend that you use the non-secure thread version of PHP (non-thread safe build of PHP). However, it is complicated to enable Zend optimizer in this version, most commercial PHP programs are inseparable from Zend optimizer, so we recommend that you still use the secure thread version of PHP. Download the latest PHP zip package from the official PHP website. This article uses PHP 5.2.9-2 and PHP 5.2.9-2 zip package.

    After the download, decompress the package to any directory (in this article, use D: \ Server \ PHP, and all the places that involve this path are represented[PHP install dir]), And rename PHP. ini-recommend in the directory to PhP. ini. Open the file in any text editor and check the following settings:

      • FastCGI. Impersonate = 1
      • CGI. fix_pathinfo = 1
      • CGI. force_redirect = 0
      • Open_basedirPoint to the path of the website containing the PHP program. [Optional]
      • Extension_dir = "./EXT"Note: In previous versions, the absolute path is often used here, but now you can use this method for general configuration.
      • Delete the semicolon before the PHP extension add-on that you want to activate, for example:
        Extension = php_mssql.dll
        Extension = php_mysql.dll
        Note: not all projects can be activated. It is best to activate only the items you need. If one item cannot run after activation, comment out the item and restart IIS.

    After the settings are complete, you can start a command prompt window (cmd.exe) to run[PHP install dir]/PHP-InfoCheck whether PHP runs correctly. If yes, a series of environment variable prompts are output.

    Part III. Configure IIS to process PHP requests

    Open the IIS manager, select your computer on the left, and click"Handler Mapping"(The Chinese version of my friend compared to the one mark, I am not sure what the project will translate into in the Chinese version of the operating system), and then click"Add module mapping..."(Add module ing).

    In the Add module mapping dialog box that appears, enter your own installation path (that is, executable (optional)[PHP install dir]/php-cgi.exe):

     

    Click OK. A confirmation dialog box is displayed, asking if you want to add the module ing. PointYesContinue.

    This completes the installation of PHP in IIS 7.x. Create a text file under your website directory with the file name suffix. PHP, such as test. PHP, the file contains only one line:

    <? PHP phpinfo ();?>

    Then browse the file in the browser (usually http: // localhost/test. php). Normally, the default information page of PHP is displayed.

    According to different configurations, the information may be different. I have installed Zend optimizer v3.3.3 In the screenshot here. By default, Zend optimizer v3.3.3 does not exist. You can download and install it on your own, the installation of Zend optimizer is the same as that of all previous versions. Even if there is no tutorial, you can install Zend optimizer by following the installation wizard step by step. I will not go into details here. In addition, the installation of MySQL and phpMyAdmin is the same. It is not related to the IIS version. I won't talk about it anymore.

    Users who have previously configured PhP4 or configured it via ISAPI in earlier versions of IIS 6.0 can find that configuring PHP in IIS 7.x using FastCGI has been greatly simplified, you don't need to copy files to system folders like PHP 4, you don't need to modify environment variables like those in earlier versions of IIS 6.0, and you don't need to set the absolute path of extension_dir like the ISAPI method ......

    All in all, in windows, PHP is not just a thing that can't be done in the past. its security, stability, and running efficiency have been greatly improved. In addition to Linux + Apache + PHP + MySQL, we can now easily use Windows + IIS + PHP + MSSQL.

    Initial address: knife blog-run php with FastCGI in iis7.x
  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.