设为首页 收藏本站
查看: 683|回复: 0

[经验分享] Using FastCGI to Host PHP Applications on IIS 6.0-TO BE CONTINUED-运维网 博客

[复制链接]
发表于 2018-12-10 08:34:34 | 显示全部楼层 |阅读模式
Introduction

This article explains how to use the Microsoft IIS FastCGI extension to set up and run PHP applications on Windows XP and Windows Server® 2003 operating systems.
What is FastCGI?

FastCGI is a standard protocol that allows the CGI executable files for application frameworks to interface with the Web server. It differs from the standard CGI protocol in that FastCGI reuses CGI processes for multiple requests, which provides a significant performance boost as compared to CGI. Support for IIS FastCGI enables IIS to host normal CGI programs like PHP or Ruby on Rails by using the FastCGI protocol, and to offer high performance and stability for production deployment of such application frameworks.
Using the IIS FastCGI support includes the following:

  • IIS Web server
  • IIS FastCGI extension
  • CGI program (such as php-cgi.exe)

The Web server dispatches HTTP requests to your application to the FastCGI component, which in turn launches the CGI program executable, and forwards the request for processing. Once the request is finished and the response is returned back to the server and sent to the client, the CGI process is reused for a subsequent request. This helps to avoid the high performance penalty of starting a new process for each request, which results in better performance and scalability in a production environment.
To learn more about the FastCGI protocol, see http://www.fastcgi.com/devkit/doc/fcgi-spec.html.
Install the FastCGI Extension for IIS 6.0 and IIS 5.1

You can download the FastCGI extension for 32-bit and 64-bit Windows XP and Windows Server 2003 here:
http://www.iis.net/extensions/fastcgi
When you run the FastCGI installer, it copies FastCGI-specific files to the "%windir%\system32\inetsrv" folder, and then registers and enables the FastCGI Web server extension. Of the files that the installer copies, note the following:

  • fcgiext.dll – This is the actual FastCGI handler that communicates with FastCGI-enabled processes for processing requests.
  • fcgiext.ini – This is the configuration file that contains the mapping of file extensions to FastCGI processes. It also contains the configuration of FastCGI process pools.
  • fcgiconfig.js – This configures the FastCGI extension. The script updates the fcgiext.ini file, modifies the IIS metabase and recycles the Web service application pools if necessary.
Download and Install PHP

The FastCGI extension is fully compatible with the current official PHP 4.4.x and PHP 5.x distribution for Windows, available from http://windows.php.net/download. Since the FastCGI extension hosts and executes php processes in a single threaded manner, it is recommended that you download and install the non-thread-safe PHP build that is available for Windows. The non-thread-safe PHP build provides a performance boost from a lack of thread safety that is acceptable for a single-concurrency environment like FastCGI.
Configure the FastCGI Extension to Work with PHP

Once PHP is installed on Windows, you have two options to configure FastCGI: use the configuration script that is provided with the installation of the FastCGI extension, or perform all the configuration tasks manually by modifying IIS configuration settings and the fcgiext.ini file.
Configure the FastCGI Extension to Work with PHP by Using the Configuration Script

The configuration script with the name fcgconfig.js is provided with the installation of the FastCGI extension. It is located in %windir%\system32\inetsrv.
To configure the FastCGI extension to work with PHP:

  • Open a command prompt.
  • Change the current directory to %windir%\system32\inetsrv.
  • Register the PHP CGI program as the one that will be processing .php extensions by running the following configuration script:
cscript fcgiconfig.js -add -section:"PHP" -extension:php -path:"C:\PHP\php-cgi.exe"  

  

Replace C:\PHP\php-cgi.exe with the path to php-cgi.exe if you installed to a directory other than C:\PHP.
Note: If you do not want to register the PHP extension to be processed by the FastCGI component on your entire server, and only want to register it for a specific Web site, add a "–site:[siteId]" argument, for example:cscript fcgiconfig.js -add -section:"PHP" -extension:php -path:"C:\PHP\php-cgi.exe" –site:1  

  

Note: For a complete list of configuration parameters that are supported by the FastCGI extension, see the FastCGI extension documentation.
Manually Configure the FastCGI Extension to Work with PHP

To manually configure the IIS and FastCGI extension, you must create script mappings for the PHP extension in the IIS metabase, and modify the fcgiext.ini file that is located in %windir%\system32\inetsrv.
To create script mapping:

  • Launch inetmgr.exe.
  • Double-click the machine icon for the local computer.
  • Right-click Web Sites and click Properties.
  • Click the Home Directory tab.
  • Click the Configuration… button.
  • Click the Add… button.
  • In the Add/Edit Application Extension Mapping dialog box, click Browse.... Navigate to the fcgiext.dll file that is located in %windir%\system32\inetsrv.
Note: If you need to use FastCGI in 32-bit mode on a 64-bit machine, navigate to %windir%\SysWOW64\inetsrv.
    8.  In the Extension text box, enter .php.
    9.  Under Verbs, in the Limit to text box, enter GET,HEAD,POST.
  10.  Ensure that the Script engine and Verify that file exists check boxes are selected.


    11.  Click OK.
To modify the fcigext.ini file:
Once the script mapping has been added, modify the fcgiext.ini file.

  • Add an extension to application mapping (php=PHP) to the [Types] section.
  • Add a [PHP] section with ExePath=c:\php\php-cgi.exe (assuming you installed PHP files to the C:\PHP folder).
[Types]  

  
php=PHP
  

  

  
[PHP]
  
ExePath=c:\php\php-cgi.exe
  

  

3. After you save the changes to the fcgiext.ini file, restart the application pool that is associated with the Web site that hosts your PHP applications.
To configure a default document in IIS:
Most PHP applications use a file named index.php as the default application document. Configure IIS to treat this file as the default content page.

  • Launch inetmgr.exe.
  • Double-click the machine icon for the local computer.
  • Right-click Web Sites and click Properties.
  • Click the Documents tab.
  • Click the Add… button.
  • In the Add Content Page dialog box, in the Default content page text box, enter index.php.
  • Click OK.

Set the FastCGI Configuration for Optimal Functionality, Security, and Performance with PHP

IIS focuses on full PHP functionality support and performance of PHP applications that are running on the FastCGI extension. In collaboration with Zend Technologies, IIS>
To obtain optimal functionality and performance, configure your server as follows:
    1.  Modify the php.ini file as follows:

  • Set fastcgi.impersonate = 1. FastCGI under IIS supports the ability to impersonate the security tokens of the calling client. This allows IIS to define the security context under which the request runs.
  • Set cgi.fix_pathinfo=1. cgi.fix_pathinfo provides *real* PATH_INFO/PATH_TRANSLATED support for CGI. Previously, PHP behavior was to set PATH_TRANSLATED to SCRIPT_FILENAME, and to not define PATH_INFO. For more information about PATH_INFO, see the cgi specifications. Setting this value to 1 will cause PHP CGI to fix its paths to conform to the specification.
  • Set cgi.force_redirect = 0.
    2.  Set the FastCGI configuration settings for the PHP section by running fcgiconfig.js as follows:

  • Set the FastCGI process pool property InstanceMaxRequests to 10000. This setting specifies that the FastCGI extension will recycle php-cgi.exe after it has processed 10000 requests successfully.
> cscript fcgiconfig.js -set -section:"PHP" -InstanceMaxRequests:10000  

  

3.  Configure the FastCGI extension to set the PHP_FCGI_MAX_REQUESTS environment variables for the PHP process to 10000.This setting instructs php-cgi.exe to recycle itself after it has processed 10000 requests successfully.  > cscript fcgiconfig.js -set -section:"PHP" -EnvironmentVars:PHP_FCGI_MAX_REQUESTS:10000

Note: You can configure InstanceMaxRequests and PHP_FCGI_MAX_REQUESTS to use numbers other than 10000. As a general rule, ensure that the value of InstanceMaxRequests is less than or equal to the value of PHP_FCGI_MAX_REQUESTS.
Test PHP CGI

After installing the FastCGI extension and registering and configuring the PHP CGI, you can request your PHP application and use it normally.
To test the PHP application, create and request a phpinfo.php page in your site that contains the following:
  

  

You should see something like the following:

Note that the Server API field indicates that PHP is hosted in FastCGI mode.
Get More Information

Use the FastCGI forums to discuss the usage of the FastCGI extension or to file bug reports:

  • IIS.NET FastCGI forums
For more information about how to run various PHP applications on IIS, see:

  • PHP on IIS portal
  • PHP community forum

Related Content


  • Articles
  • Set Up FastCGI for PHP
  • Configure PHP Process Recycling Behavior
  • Installing PHP on Windows Vista with FastCGI
  • Using FastCGI to Host PHP Applications on IIS 6.0



运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-649631-1-1.html 上篇帖子: XP系统 iis不能浏览aspx,asp但能浏览html-my 下篇帖子: IIS服务器应用程序不可用
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表