<?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>简单生活@NET &#187; 共存</title>
	<atom:link href="http://lee.kometo.com/archives/tag/%e5%85%b1%e5%ad%98/feed" rel="self" type="application/rss+xml" />
	<link>http://lee.kometo.com</link>
	<description>正确的判断来自经验，但经验往往来自错误的判断</description>
	<lastBuildDate>Tue, 10 Aug 2010 11:01:45 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Windows平台下Apache+PHP4+PHP5+FastCGI安装笔记</title>
		<link>http://lee.kometo.com/archives/97</link>
		<comments>http://lee.kometo.com/archives/97#comments</comments>
		<pubDate>Sun, 26 Oct 2008 21:05:48 +0000</pubDate>
		<dc:creator>kometo</dc:creator>
				<category><![CDATA[WEB应用开发]]></category>
		<category><![CDATA[深入PHP]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[CGI]]></category>
		<category><![CDATA[fastcgi]]></category>
		<category><![CDATA[php4]]></category>
		<category><![CDATA[php5]]></category>
		<category><![CDATA[共存]]></category>

		<guid isPermaLink="false">http://lee.kometo.com/?p=97</guid>
		<description><![CDATA[APACHE环境配置了一Apache+PHP4+PHP5+FastCGI环境，请注意：此配置实用的 CGI 运行方式，而没有使用常见的 Apache modules 方式。]]></description>
			<content:encoded><![CDATA[<h3>Go PHP5</h3>
<p>很多开发组织已经开始参与到 <a href="http://www.ooso.net/index.php/archives/348" target="_blank">Go PHP5</a> 的活动中来了，PHP官方也早已经声明于2007年底停止对PHP4的所有技术支持，看来PHP5/6的广泛应用已经是不可抗拒的浪潮了，仅仅是时间问题，而且时间不会太长。</p>
<h3>Apache+PHP+FastCGI</h3>
<p>对于目前的过渡阶段，很多开发者还是需要一个可以实现PHP4和PHP5共存的开发环境，这两天尝试在Windows下使用APACHE环境配置了一个PHP4和PHP5共存的环境，请注意：此配置使用 CGI 运行方式，而没有使用常见的 Apache modules 方式。我曾经尝试使用 Apache modules方式配置双PHP，但没有成功。</p>
<p>关键特性：</p>
<ol>
<li>Windows+Apache+PHP（Apache2.0下测试）</li>
<li>PHP4+PHP5共存</li>
<li>FastCGI</li>
</ol>
<p>以下是配置中用到的Apache Conf：</p>
<p><span id="more-97"></span></p>
<pre lang="ini">
# Apache加载PHP的配置，
# 直接附加到httpd.conf结尾
# 或使用 include 包含
AddType application/x-httpd-php .php
AddType application/x-httpd-php .php4
AddType application/x-httpd-php .php5

ScriptAlias /php4/ "D:/server/php4/"
Action php-script-5 "/php5/php-cgi.exe"
<Directory "D:/server/php4">
    AllowOverride None
    Options None
    Order allow,deny
    Allow from all
</Directory>
Action php-script-4 "/php4/php.exe"

ScriptAlias /php5/ "D:/server/php5/"
Action php-script-5 "/php5/php-cgi.exe"
<Directory "D:/server/php5">
    AllowOverride None
    Options None
    Order allow,deny
    Allow from all
fcgid-2.2-w32.zip
</Directory>

AddHandler php-script-4 .php4
AddHandler php-script-5 .php5

#默认的使用的版本，可以在.htaccess文件中修改
AddHandler php-script-4 .php
</pre>
<p>简单说明下：PHP4和PHP5均使用手动安装包（不是Installer)，分别解压到 d:\server\php4 和 d:\server\php5。使用AddType命令指定扩展名对应关系：PHP4使用扩展名 &#8220;php&#8221;,PHP5使用扩展名“php5”。AddType可以再 .httaccess文件中使用，以实现修改不同目录的默认PHP版本。</p>
<p>PHP4包解压后需要把dlls和sapi目录下的所有文件拷贝到PHP4的根目录，既和PHP.exe放在一起。php.ini文件直接放在PHP4/5的根目录中即可(d:\server\php4 和 d:\server\php5)。注意要确保系统其它位置不要出现php.ini文件，否则可能会覆盖有效的配置。PHP本身的配置我就不说了，自己查资料吧。</p>
<h3>FastCGI</h3>
<p>CGI方式运行PHP最大的缺点是效率低，可以配合Fast-cgi使用，Conf文件修改如下，增加最后3行即可。</p>
<p>除了FastCGI另外还有一个fcgid也可以是参考</p>
<pre lang="ini">
# Apache Conf 直接附加的配置文件末尾
LoadModule fastcgi_module modules/mod_fastcgi-2.4.2-AP20.dll
FastCgiServer "D:/server/php4/php.exe" -processes 4
# 如果PHP5的不能正常工作，可以用 #号 注释掉下一行，似乎这个平台下，PHP5+FastCGI还是有些问题
FastCgiServer "D:/server/php5/php-cgi.exe" -processes 4

# 以下是未经验证的，仅供参考的配置语句
# FastCgiSuexec /usr/sbin/suexec
# FastCgiServer /var/www/igenus/php-cgi/php -processes 10
# FastCgiConfig -singleThreshold 100 -killInterval 300 -autoUpdate -idle-timeout 240 -pass-header HTTP_AUTHORIZATION
</pre>
<h3>相关PHP配置(可选的)</h3>
<pre lang='ini'>
; ==============================================================
; 常用的PHP的附加配置，直接附加到PHP.ini文件的尾部
; 另：CGI/FastCGI方式下运行的PHP，php.ini文件的最好位置就是放在PHP.exe所在的目录

; 这个目录必须设定好！！
extension_dir = "D:\server\php5\ext"
extension=php_mysql.dll
; extension=php_mysqli.dll
; extension=php_pdo.dll
; extension=php_pdo_mysql.dll
extension=php_mbstring.dll
extension=php_mcrypt.dll
extension=php_gd2.dll
extension=php_bz2.dll
extension=php_curl.dll

; doc_root = d:\wwwroot

; cgi.force_redirect = 0
; cgi.fix_pathinfo=1
; fastcgi.impersonate = 1; 

; session.save_handler = files
; session.save_path = /tmp
; session.use_cookies = 1
; session.use_only_cookies = 1

; file_uploads = On
; upload_tmp_dir =
; upload_max_filesize = 2M
; post_max_size = 8M
; memory_limit = 8M

; max_execution_time = 30
; max_input_time = 60

display_errors = on
error_reporting  =  E_ALL
; log_errors = off
; error_log = d:\server\php5\logs\error.log

; mysql.connect_timeout = 1
</pre>
<p>参考资料</p>
<ol>
<li>有关Fast CGI 请参阅：<a href="http://blogme.cn/node/6529">http://blogme.cn/node/6529</a> <a href="http://www.fastcgi.com/" target="_blank">http://www.fastcgi.com/</a></li>
<li>
有关Go PHP5 请参阅：<a href="http://www.ooso.net/index.php/archives/348">http://www.ooso.net/index.php/archives/348</a></li>
<li>这里还有篇比较罗嗦的指南，也可以看看：<a href="http://www.seji.cn/tech/infoView/Article_122.html">http://www.seji.cn/tech/infoView/Article_122.html</a></li>
<li>最后还有最应该看的：<a href="http://www.php.net/manual/en/install.windows.php">PHP安装手册</a></li>
</ol>
<blockquote><p><p>！！！经反复测试<strong>APACHE2.2+fastCGI+PHP5.*</strong>在windows平台下运行存在问题，使用以上配置无法工作，使用Apache2.0一切正常！！！<br />
相关错误提示(Apache&#8217;s errors.log)类似：<br />
<strong> terminated with exit with status &#8217;0&#8242;<br />
FastCGI: incomplete headers (0 bytes) received from server</strong><br />
我的测试版本是：PHP5.2.6 / FastCGI 2.4.6-AP22.dll /Apache 2.2 / Windows2003</p>
<p>表现为：</p>
<ul>
<li>在不启用FastCGI时，PHP5的反应非常迟钝，特别是在加载了Mysql扩展之后，很奇怪的现象！！</li>
<li>启用FastCGI时不能正常工作,而PHP4配合相同的设定确工作的很好<br />
相关的错误信息可以参看:</p>
<ul>
<li>FastCGI: server &#8220;D:/server/php5/php-cgi.exe&#8221; (pid 1708) terminated with exit with status &#8217;0&#8242;</li>
<li>(OS 109)管道已结束。  : FastCGI: comm with server &#8220;D:/server/php5/php-cgi.exe&#8221; aborted: GetOverlappedResult() failed</li>
<li>FastCGI: incomplete headers (0 bytes) received from server &#8220;D:/server/php5/php-cgi.exe&#8221;</li>
</ul>
</li>
</blockquote>
]]></content:encoded>
			<wfw:commentRss>http://lee.kometo.com/archives/97/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
