<?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; php4</title>
	<atom:link href="http://lee.kometo.com/archives/tag/php4/feed" rel="self" type="application/rss+xml" />
	<link>http://lee.kometo.com</link>
	<description>正确的判断来自经验，但经验往往来自错误的判断</description>
	<lastBuildDate>Mon, 06 Feb 2012 02:26:17 +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>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>Emeric lee</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>修正：2010.3</h3>
<p>1.PHP自5.3版起默认不在支持针对Windows的VC6编译版本，只提供VC9版本的，而APAche官方提供的Apache Windows编译包都是VC6的。所以我们需要使用第三方编译的VC9版本的Apache。</p>
<p>2.PHP 的 None Thread Safe 版本适用于CGI/FastCGI方式，而相应的Thread Safe版本适用于SAPI和Mod方式</p>
<p>3. <a href="http://www.apachelounge.com/download/">http://www.apachelounge.com/download/</a> 这里提供了大量适用于Windows的LAMP有关预编译包，包括VC9版本的Apache和FastCGI，这个网站也是PHP官方推荐的网站。</p>
<h3>原文</h3>
<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>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;"># Apache加载PHP的配置，
# 直接附加到httpd.conf结尾
# 或使用 include 包含
AddType application/x-httpd-php .php
AddType application/x-httpd-php .php4
AddType application/x-httpd-php .php5
&nbsp;
ScriptAlias /php4/ <span style="color: #933;">&quot;D:/server/php4/&quot;</span>
Action php-script-<span style="">5</span> <span style="color: #933;">&quot;/php5/php-cgi.exe&quot;</span>
&nbsp;
    AllowOverride None
    Options None
    Order allow,deny
    Allow from all
&nbsp;
Action php-script-<span style="">4</span> <span style="color: #933;">&quot;/php4/php.exe&quot;</span>
&nbsp;
ScriptAlias /php5/ <span style="color: #933;">&quot;D:/server/php5/&quot;</span>
Action php-script-<span style="">5</span> <span style="color: #933;">&quot;/php5/php-cgi.exe&quot;</span>
&nbsp;
    AllowOverride None
    Options None
    Order allow,deny
    Allow from all
fcgid-<span style="">2.2</span>-w32.zip
&nbsp;
AddHandler php-script-<span style="">4</span> .php4
AddHandler php-script-<span style="">5</span> .php5
&nbsp;
#默认的使用的版本，可以在.htaccess文件中修改
AddHandler php-script-<span style="">4</span> .php</pre></div></div>

<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>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;"># Apache Conf 直接附加的配置文件末尾
LoadModule fastcgi_module modules/mod_fastcgi-2.4.2-AP20.dll
FastCgiServer <span style="color: #933;">&quot;D:/server/php4/php.exe&quot;</span> -processes <span style="">4</span>
# 如果PHP5的不能正常工作，可以用 #号 注释掉下一行，似乎这个平台下，PHP5+FastCGI还是有些问题
FastCgiServer <span style="color: #933;">&quot;D:/server/php5/php-cgi.exe&quot;</span> -processes <span style="">4</span>
&nbsp;
# 以下是未经验证的，仅供参考的配置语句
# FastCgiSuexec /usr/sbin/suexec
# FastCgiServer /var/www/igenus/php-cgi/php -processes <span style="">10</span>
# FastCgiConfig -singleThreshold <span style="">100</span> -killInterval <span style="">300</span> -autoUpdate -idle-timeout <span style="">240</span> -pass-header HTTP_AUTHORIZATION</pre></div></div>

<h3>相关PHP配置(可选的)</h3>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">; ==============================================================</span>
<span style="color: #666666; font-style: italic;">; 常用的PHP的附加配置，直接附加到PHP.ini文件的尾部</span>
<span style="color: #666666; font-style: italic;">; 另：CGI/FastCGI方式下运行的PHP，php.ini文件的最好位置就是放在PHP.exe所在的目录</span>
&nbsp;
<span style="color: #666666; font-style: italic;">; 这个目录必须设定好！！</span>
<span style="color: #000099;">extension_dir</span> <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;D:\server\php5\ext&quot;</span>
<span style="color: #000099;">extension</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">php_mysql.dll</span>
<span style="color: #666666; font-style: italic;">; extension=php_mysqli.dll</span>
<span style="color: #666666; font-style: italic;">; extension=php_pdo.dll</span>
<span style="color: #666666; font-style: italic;">; extension=php_pdo_mysql.dll</span>
<span style="color: #000099;">extension</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">php_mbstring.dll</span>
<span style="color: #000099;">extension</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">php_mcrypt.dll</span>
<span style="color: #000099;">extension</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">php_gd2.dll</span>
<span style="color: #000099;">extension</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">php_bz2.dll</span>
<span style="color: #000099;">extension</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">php_curl.dll</span>
&nbsp;
<span style="color: #666666; font-style: italic;">; doc_root = d:\wwwroot</span>
&nbsp;
<span style="color: #666666; font-style: italic;">; cgi.force_redirect = 0</span>
<span style="color: #666666; font-style: italic;">; cgi.fix_pathinfo=1</span>
<span style="color: #666666; font-style: italic;">; fastcgi.impersonate = 1; </span>
&nbsp;
<span style="color: #666666; font-style: italic;">; session.save_handler = files</span>
<span style="color: #666666; font-style: italic;">; session.save_path = /tmp</span>
<span style="color: #666666; font-style: italic;">; session.use_cookies = 1</span>
<span style="color: #666666; font-style: italic;">; session.use_only_cookies = 1</span>
&nbsp;
<span style="color: #666666; font-style: italic;">; file_uploads = On</span>
<span style="color: #666666; font-style: italic;">; upload_tmp_dir =</span>
<span style="color: #666666; font-style: italic;">; upload_max_filesize = 2M</span>
<span style="color: #666666; font-style: italic;">; post_max_size = 8M</span>
<span style="color: #666666; font-style: italic;">; memory_limit = 8M</span>
&nbsp;
<span style="color: #666666; font-style: italic;">; max_execution_time = 30</span>
<span style="color: #666666; font-style: italic;">; max_input_time = 60</span>
&nbsp;
<span style="color: #000099;">display_errors</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> on</span>
<span style="color: #000099;">error_reporting</span>  <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">  E_ALL</span>
<span style="color: #666666; font-style: italic;">; log_errors = off</span>
<span style="color: #666666; font-style: italic;">; error_log = d:\server\php5\logs\error.log</span>
&nbsp;
<span style="color: #666666; font-style: italic;">; mysql.connect_timeout = 1</span></pre></div></div>

<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>！！！经反复测试<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>
</ul>
</blockquote>
]]></content:encoded>
			<wfw:commentRss>http://lee.kometo.com/archives/97/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

