<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>裁纸刀下 &#187; FastCGI</title>
	<atom:link href="http://ofcss.com/tags/fastcgi/feed" rel="self" type="application/rss+xml" />
	<link>http://ofcss.com</link>
	<description>独立 自由 诚信 宽容 责任 平常心</description>
	<lastBuildDate>Fri, 20 Apr 2012 04:08:47 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>在 IIS 7.x 中用 FastCGI 运行 PHP</title>
		<link>http://ofcss.com/2009/06/08/using-fastcgi-to-host-php-applications-on-iis-7x.html</link>
		<comments>http://ofcss.com/2009/06/08/using-fastcgi-to-host-php-applications-on-iis-7x.html#comments</comments>
		<pubDate>Mon, 08 Jun 2009 07:16:06 +0000</pubDate>
		<dc:creator>小李刀刀</dc:creator>
				<category><![CDATA[所谓技术]]></category>
		<category><![CDATA[FastCGI]]></category>
		<category><![CDATA[IIS]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Windows 7]]></category>

		<guid isPermaLink="false">http://wukangrui.net/2009/06/08/%e5%9c%a8-iis-7x-%e4%b8%ad%e7%94%a8-fastcgi-%e8%bf%90%e8%a1%8c-php.html</guid>
		<description><![CDATA[实际上从微软提供 FastCGI 支持以来，在 IIS官方站点上就一直有关于如何配置 IIS 各个版本下的 FastCGI 支持以及使用 FastCGI 方式运行 PHP 的详细教程，所以早在 IIS 7.0 刚刚出现没多久，微软就已经提供了在 IIS 上运行 PHP 的一种更优化的方式—— FastCGI。但是直到 IIS 7.5 随着 Windows 7 出现，网上还有很多的“大虾”在教菜鸟们如何在 IIS 7.x 下用配置ISAPI支持的方式（甚至是PHP手册上不推荐的拷贝文件到系统目录的方式）来支持 PHP。本文介绍一下在 IIS7.x 中启用 FastCGI，以及配置 PHP 的方法。 我的配置环境是 Windows 7 x64 + IIS 7.5，但是本文的内容在Windows 7.x 版本中应该是完全通用的，因为 FastCGI 正是从 IIS 7.0 开始成为内置组件的。至于之前的版本，需要额外安装 FastCGI 支持，配置上也略有不同。 &#160; Part I. 启用 [...]]]></description>
			<content:encoded><![CDATA[<p>实际上从微软提供 <a title="FastCGI官方网站" href="http://www.fastcgi.com/" rel="nofollow" target="_blank">FastCGI</a> 支持以来，在 <a href="http://www.iis.net/" rel="nofollow" target="_blank">IIS官方站点</a>上就一直有关于如何配置 <a title="微软IIS官方网站" href="http://www.iis.net/" rel="nofollow" target="_blank">IIS</a> 各个版本下的 FastCGI 支持以及使用 FastCGI 方式运行 PHP 的详细教程，所以早在 IIS 7.0 刚刚出现没多久，微软就已经提供了在 IIS 上运行 PHP 的一种更优化的方式—— FastCGI。但是直到 IIS 7.5 随着 Windows 7 出现，网上还有很多的“大虾”在教菜鸟们如何在 IIS 7.x 下用配置ISAPI支持的方式（甚至是PHP手册上不推荐的拷贝文件到系统目录的方式）来支持 PHP。本文介绍一下在 IIS7.x 中启用 FastCGI，以及配置 PHP 的方法。</p>
<p> <span id="more-666"></span>
<p>我的配置环境是 Windows 7 x64 + IIS 7.5，但是本文的内容在Windows 7.x 版本中应该是完全通用的，因为 FastCGI 正是从 IIS 7.0 开始成为内置组件的。至于之前的版本，需要额外安装 FastCGI 支持，配置上也略有不同。</p>
<p>&#160;</p>
<h3>Part I. 启用 IIS 7.x 中的 FastCGI 支持    <br /></h3>
<p>依次打开 <strong>控制面板 | 程序和组件 | 开启或关闭Windows功能</strong>，英文版对应操作为 <strong>Control Panel | Programs and Features | Turn Windows Features On or Off</strong>. 然后按下图所示启用 FastCGI （勾选 CGI 将同时启用 CGI 和 FastCGI 支持）。其它项你应该根据自己的需要选择，我这里是为了突出显示才去掉了其他项目的勾选。</p>
<p align="center"><a href="http://file.wukangrui.com/attachments/2009/06/400a630a2ef1.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="图一" border="0" alt="图一" src="http://file.wukangrui.com/attachments/2009/06/thumb.png" width="433" height="506" /></a> </p>
<p>如果是 IIS7.0，微软已经发布了一系列升级补丁来修正其中内置的 FastCGI 模块已知的部分问题，你可以根据自己的系统下载对应的补丁进行升级：</p>
<li><a href="http://www.microsoft.com/downloads/info.aspx?na=22&amp;p=1&amp;SrcDisplayLang=en&amp;SrcCategoryId=&amp;SrcFamilyId=&amp;u=%2fdownloads%2fdetails.aspx%3fFamilyID%3dd0343911-1775-4aef-8c99-5f13862ac386%26DisplayLang%3den" target="_blank">Update for Windows Server 2008</a> </li>
<li><a href="http://www.microsoft.com/downloads/info.aspx?na=22&amp;p=3&amp;SrcDisplayLang=en&amp;SrcCategoryId=&amp;SrcFamilyId=&amp;u=%2fdownloads%2fdetails.aspx%3fFamilyID%3d70278393-3291-4aa1-870b-0e9b0907bddf%26DisplayLang%3den" target="_blank">Update for Windows Server 2008 x64 Edition</a> </li>
<li><a href="http://www.microsoft.com/downloads/info.aspx?na=22&amp;p=5&amp;SrcDisplayLang=en&amp;SrcCategoryId=&amp;SrcFamilyId=&amp;u=%2fdownloads%2fdetails.aspx%3fFamilyID%3d98e06637-0f00-45d5-83c5-ed1b41fd6a7b%26DisplayLang%3den" target="_blank">Update for Windows Server 2008 for Itanium-based Systems</a> </li>
<li><a href="http://www.microsoft.com/downloads/info.aspx?na=22&amp;p=2&amp;SrcDisplayLang=en&amp;SrcCategoryId=&amp;SrcFamilyId=&amp;u=%2fdownloads%2fdetails.aspx%3fFamilyID%3d19600729-8470-4956-a276-200450d814bd%26DisplayLang%3den" target="_blank">Update for Windows Vista SP1</a> </li>
<li><a href="http://www.microsoft.com/downloads/info.aspx?na=22&amp;p=4&amp;SrcDisplayLang=en&amp;SrcCategoryId=&amp;SrcFamilyId=&amp;u=%2fdownloads%2fdetails.aspx%3fFamilyID%3dc7066c3b-dcf7-4441-87bc-f7dcb51067d0%26DisplayLang%3den" target="_blank">Update for Windows Vista SP1 for x64 based Systems</a>
<p>&#160;</p>
<h3>Part II. 安装和配置PHP      <br /></h3>
<p>微软官方文章里建议使用非安全线程版本的PHP(non-thread safe build of php)，但是由于该版本下的Zend Optimizer的启用会比较复杂，而大部分商业PHP程序都是离不开Zend Optimizer的，所以建议仍然采用安全线程版本的PHP。请从 <a title="PHP官方网站" href="http://www.php.net/" rel="nofollow" target="_blank">PHP官方网站</a> 下载最新版本的 PHP Zip格式压缩包，本文写作时使用的是 PHP 5.2.9-2 版，下载地址：<a title="PHP 5.2.9-2 zip package" href="http://www.php.net/get/php-5.2.9-2-Win32.zip/from/a/mirror" rel="nofollow" target="_blank">PHP 5.2.9-2 zip package</a> 。</p>
<p>下载以后，将其解压缩到任意目录（本文中使用 D:\server\php，后面所有涉及到此路径的地方均表示为 <strong>[PHP Install Dir]</strong>），然后将目录中的 php.ini-recommend 改名为 php.ini 。用任意的文本编辑器打开这个文件，查找并确认以下设置：</p>
<ul>
<li><strong>fastcgi.impersonate = 1</strong> </li>
<li><strong>cgi.fix_pathinfo=1</strong> </li>
<li><strong>cgi.force_redirect = 0</strong> </li>
<li><strong>open_basedir</strong> 指向包含 php 程序的网站路径。 【可选项】 </li>
<li><strong>extension_dir = &quot;./ext&quot; </strong>;注意：以往版本中这里往往要使用绝对路径，但是现在可以用这样的方式进行通用配置。 </li>
<li>删除你需要激活的php扩展加载项前面的分号，例如：        <br />extension=php_mssql.dll         <br />extension=php_mysql.dll         <br />注意：不是所有的项目都可以激活的，最好只激活你用到的，如果激活某一项之后运行不了，请重新注释掉该项并重启IIS。 </li>
</ul>
<p>设置完毕以后，可以启动一个命令提示行窗口（cmd.exe），运行 <strong>[PHP Install Dir]/php –info</strong> 检查一下 php 是否可以正确运行，如果正确，会输出一系列的环境变量提示等。</p>
<p>&#160;</p>
<h3>Part III. 配置 IIS 处理 PHP 请求      <br /></h3>
<p>打开 IIS 管理器，左边选择你的计算机，中间窗口点击“<strong>Handler Mapping</strong>”（中文版的朋友对照一下图标了，我不太确定在中文版操作系统中这个项目会翻译成什么），然后在右边点击“<strong>Add Module Mapping…</strong>”（<strong>添加模块映射</strong>）。</p>
</li>
<p align="center"><a href="http://file.wukangrui.com/attachments/2009/06/iisaddhandlermapping.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="IIS-Add-Handler-Mapping" border="0" alt="IIS-Add-Handler-Mapping" src="http://file.wukangrui.com/attachments/2009/06/iisaddhandlermapping-thumb.png" width="916" height="689" /></a> </p>
<p>在弹出的 Add Module Mapping 对话框中，按照下图填写（Executable(optional)一项请填写你自己的安装路径，即 <strong>[PHP Install Dir]/php-cgi.exe</strong> ）：</p>
<p align="center"><a href="http://file.wukangrui.com/attachments/2009/06/addmodulemapping.gif"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Add Module Mapping" border="0" alt="Add Module Mapping" src="http://file.wukangrui.com/attachments/2009/06/addmodulemapping-thumb.gif" width="475" height="411" /></a>&#160;</p>
<p>填写好之后，点 OK，会弹出一个确认对话框，问你是不是真的要添加这个模块映射。点 <strong>Yes</strong> 继续。</p>
<p align="center"><a href="http://file.wukangrui.com/attachments/2009/06/file3.jpg"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="file3" border="0" alt="file3" src="http://file.wukangrui.com/attachments/2009/06/file3-thumb.jpg" width="415" height="167" /></a> </p>
<p>到此就完成了 PHP 在 IIS 7.x 下的安装，在你的网站目录下创建一个文本文件，文件名后缀为.php，比如test.php，该文件的内容只有一行：</p>
<blockquote><p><font style="background-color: #ffffff">&lt;?php phpinfo(); ?&gt;</font></p>
</blockquote>
<p>然后用浏览器浏览这个文件(通常是<a href="http://localhost/test.php">http://localhost/test.php</a>)，正常情况下，就会看到PHP的默认信息页面了。</p>
<p align="center"><a href="http://file.wukangrui.com/attachments/2009/06/phpinfo.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="phpinfo" border="0" alt="phpinfo" src="http://file.wukangrui.com/attachments/2009/06/phpinfo-thumb.png" width="613" height="816" /></a> </p>
<p>根据不同的配置，看到的信息可能有所不同，我这里的抓图已经安装了 Zend Optimizer v3.3.3，默认当然是没有的，你可以自己下载并安装，Zend Optimizer 的安装和以前所有版本的一样，就算没有教程，跟着安装向导一步一步选择也能成功安装。我这里就不赘述了。此外还有 MySQL、PhpMyAdmin 等的安装，也都是一样的。虽然相关，但都和 IIS 版本无关。就不讲了。</p>
<p>以前配置过PHP4，或者在 IIS 6.0 以前版本中以 ISAPI 方式配置过的朋友应该能发现，使用 FastCGI 方式在 IIS 7.x 中配置 PHP，已经大大简化，不用像 PHP 4那样向系统文件夹拷贝文件，不用像 IIS 6.0 以前版本那样修改环境变量，而且也不像 ISAPI 方式那样要设置 extension_dir 的绝对路径……</p>
<p>总而言之，PHP 在 Windows 下已经不像以前一样仅仅是不得以而为之的一个东西，它的安全性、稳定性、运行效率已经大大提高。除了 Linux + Apache + PHP + MySQL，我们现在也可以很方便地使用 Windows + IIS + PHP + MSSQL 了。</p>
<h3  class="related_post_title">相关日志</h3><ul class="related_post"><li>2008-06-23 -- <a href="http://ofcss.com/2008/06/23/fastcgi-for-php-in-iis.html" title="微软官方FastCGI，PHP成为IIS“一等公民”">微软官方FastCGI，PHP成为IIS“一等公民”</a></li><li>2009-07-05 -- <a href="http://ofcss.com/2009/07/05/php-5-3-0-release-new-feature.html" title="PHP 5.3.0 发布">PHP 5.3.0 发布</a></li><li>2009-06-20 -- <a href="http://ofcss.com/2009/06/20/icbc-u-key-in-windows-7-x64.html" title="工行U盾在Windows 7 x64版下的使用">工行U盾在Windows 7 x64版下的使用</a></li><li>2009-06-05 -- <a href="http://ofcss.com/2009/06/05/uncharted-waters-4-in-windows7-x64.html" title="Windows 7 兼容性展示：大航海时代4">Windows 7 兼容性展示：大航海时代4</a></li><li>2009-05-24 -- <a href="http://ofcss.com/2009/05/24/sql-express-2008-x64-integration-with-visual-studio-2008-sp1.html" title="Visual Studio 2008 搭配64位SQL Server的问题解决方案">Visual Studio 2008 搭配64位SQL Server的问题解决方案</a></li><li>2009-05-23 -- <a href="http://ofcss.com/2009/05/23/google-chrome-in-windows7-x64.html" title="windows 7 x64 上的Google Chrome">windows 7 x64 上的Google Chrome</a></li><li>2009-05-16 -- <a href="http://ofcss.com/2009/05/16/window7-beta-dvd-from-microsoft.html" title="微软发放的Windows 7测试版光盘">微软发放的Windows 7测试版光盘</a></li><li>2008-06-04 -- <a href="http://ofcss.com/2008/06/04/unix-timestamp-in-asp.html" title="在ASP中实现UNIX时间戳">在ASP中实现UNIX时间戳</a></li><li>2008-05-23 -- <a href="http://ofcss.com/2008/05/23/disadvantages-of-discuz-ucenter.html" title="给UCenter的拥蹩们泼点冷水">给UCenter的拥蹩们泼点冷水</a></li><li>2007-11-19 -- <a href="http://ofcss.com/2007/11/19/install-eacceleartor-in-dreamhost.html" title="如何在DreamHost主机上安装eAcceleartor支持[翻译]">如何在DreamHost主机上安装eAcceleartor支持[翻译]</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://ofcss.com/2009/06/08/using-fastcgi-to-host-php-applications-on-iis-7x.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>微软官方FastCGI，PHP成为IIS“一等公民”</title>
		<link>http://ofcss.com/2008/06/23/fastcgi-for-php-in-iis.html</link>
		<comments>http://ofcss.com/2008/06/23/fastcgi-for-php-in-iis.html#comments</comments>
		<pubDate>Mon, 23 Jun 2008 19:46:00 +0000</pubDate>
		<dc:creator>小李刀刀</dc:creator>
				<category><![CDATA[乱七八糟]]></category>
		<category><![CDATA[FastCGI]]></category>
		<category><![CDATA[IIS]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://wukangrui.net/?p=283</guid>
		<description><![CDATA[The IIS Team is eager to announce the official release of Microsoft FastCGI Extension for IIS 6.0 as a free download. For the first time, we are providing hosters and PHP developers full support for a stack of technology that enables reliable, scalable PHP hosting on production Internet Information Services 6.0 (IIS 6) Web servers. [...]]]></description>
			<content:encoded><![CDATA[<p><!---5d9980f9--></p>
<blockquote><p>The IIS Team is eager to announce the official release of Microsoft FastCGI Extension for IIS 6.0 as a <a href="http://www.iis.net/downloads/default.aspx?tabid=34&amp;g=6&amp;i=1521">free download</a>. For the first time, we are providing hosters and PHP developers full support for a stack of technology that enables reliable, scalable PHP hosting on production Internet Information Services 6.0 (IIS 6) Web servers. (Note: The FastCGI module is built in to Windows Server 2008.)</p></blockquote>
<p>　　以往在Windows 上配置服务器的PHP环境，虽然有无数的经验，无数的文章，但是仍然不能解决所有需求。因此“LAMP”集成安装包才会如此盛行。然而除了PHP，我们有时候也并不愿意放弃ASP和ASP.NET，毕竟Linux不论有多少好处，还有那么多游戏不能在上面运行，那么多软件不能在上面运行。为了工作效率和娱乐，更多的人愿意在虚拟机或者单独的分区里装个Linux来做学习之用。<span id="more-283"></span></p>
<p>　　很多人在Windows上配置了Apache，PHP，MySQL，然后到处打听如何让ASP或者ASP.NET得以运行。或者让Apache和IIS可以并行。</p>
<p>　　这一切都源于PHP（不光PHP，还有Perl，JSP等等各种CGI）在IIS上的地位低下，运行效率低，功能不全，不稳定……</p>
<p>　　其实反过来ASP和ASP.NET在Apache上的情况是更糟的，至少我们可以让主流的所有PHP应用都在WIMP（Windows + IIS + MySQL + PHP）上跑得很好，但是几乎不能让任何主流的ASP或者ASP.NET在Apache上正常运行。</p>
<p>　　但是微软很早就开始与PHP开发人员的合作努力必然是会开花结果的。2007年的时候微软IIS小组开始发布FastCGI，如今正式版已经可以支持IIS6.0、IIS7.0，甚至内置在Windows Server 2008上。主机商和试用者的反应都不错。IIS有微软官方团队在努力，PHP有Zend在推动，强强联合带来的信心更是异常强大。</p>
<p>　　FastCGI允许以FastCGI模式在IIS上运行PHP，而不是采用以往的ISAPI方式，这样更接近于Linux下的运行状况。即使在Linux下，也会选择用FastCGI模式来为PHP提速。</p>
<p>　　从<a href="http://www.iis.net/php">www.iis.net/php</a>下载最新的FastCGI扩展安装包，安装到Windows上，然后下载一个PHP的ZIP包解压到任意目录，照着IIS.NET上的配置说明对php.ini做简单修改，再对FastCGIExt.ini做一下配置。为IIS站点加上php扩展名关联。一切都和以前的配置方式差不多。但是不需要再修改环境变量啊，重启服务器啊，拷贝某个文件到Windows目录之类的了，回收一下应用池，一切OK了。</p>
<p>　　在没装Zend Optimizer的情况下打开PHP站点测试一下，不用做基准测试，不用探针来测试，凭感觉都能很明显的感觉到速度的提升。然后装上Zend Optimizer，试试吧，的确稳定了很多，快速了很多。</p>
<p>　　微软的FastCGI并不只是针对PHP的扩展，实际上在FastCGI配置文件里，你可以通过</p>
<div class="codeText">
<div class="codeHead">C++代码</div>
<ol class="dp-cpp">
<li class="alt"><span><span>TYPE]   </span></span></li>
<li><span>php=PHP   </span></li>
<li class="alt"><span>cgi=PERL   </span></li>
<li><span>  </span></li>
<li class="alt"><span>[PHP]   </span></li>
<li><span>&#8230;&#8230;   </span></li>
<li class="alt"><span>  </span></li>
<li><span>[PERL]   </span></li>
<li class="alt"><span>&#8230;&#8230;..   </span></li>
</ol>
</div>
<p>　　这样的形式继续添加自己的扩展，全都以FastCGI方式运行。</p>
<p>　　FastCGI扩展的免费下载地址：<a href="http://www.iis.net/downloads/default.aspx?tabid=34&amp;g=6&amp;i=1521">free download</a></p>
<h3  class="related_post_title">相关日志</h3><ul class="related_post"><li>2009-06-08 -- <a href="http://ofcss.com/2009/06/08/using-fastcgi-to-host-php-applications-on-iis-7x.html" title="在 IIS 7.x 中用 FastCGI 运行 PHP">在 IIS 7.x 中用 FastCGI 运行 PHP</a></li><li>2009-07-05 -- <a href="http://ofcss.com/2009/07/05/php-5-3-0-release-new-feature.html" title="PHP 5.3.0 发布">PHP 5.3.0 发布</a></li><li>2008-06-04 -- <a href="http://ofcss.com/2008/06/04/unix-timestamp-in-asp.html" title="在ASP中实现UNIX时间戳">在ASP中实现UNIX时间戳</a></li><li>2008-05-23 -- <a href="http://ofcss.com/2008/05/23/disadvantages-of-discuz-ucenter.html" title="给UCenter的拥蹩们泼点冷水">给UCenter的拥蹩们泼点冷水</a></li><li>2007-11-19 -- <a href="http://ofcss.com/2007/11/19/install-eacceleartor-in-dreamhost.html" title="如何在DreamHost主机上安装eAcceleartor支持[翻译]">如何在DreamHost主机上安装eAcceleartor支持[翻译]</a></li><li>2005-06-12 -- <a href="http://ofcss.com/2005/06/12/about-website-safety.html" title="关于网站的安全性">关于网站的安全性</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://ofcss.com/2008/06/23/fastcgi-for-php-in-iis.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

