Windows平台下Apache+PHP4+PHP5+FastCGI安装笔记
修正:2010.3
1.PHP自5.3版起默认不在支持针对Windows的VC6编译版本,只提供VC9版本的,而APAche官方提供的Apache Windows编译包都是VC6的。所以我们需要使用第三方编译的VC9版本的Apache。
2.PHP 的 None Thread Safe 版本适用于CGI/FastCGI方式,而相应的Thread Safe版本适用于SAPI和Mod方式
3. http://www.apachelounge.com/download/ 这里提供了大量适用于Windows的LAMP有关预编译包,包括VC9版本的Apache和FastCGI,这个网站也是PHP官方推荐的网站。
原文
Go PHP5
很多开发组织已经开始参与到 Go PHP5 的活动中来了,PHP官方也早已经声明于2007年底停止对PHP4的所有技术支持,看来PHP5/6的广泛应用已经是不可抗拒的浪潮了,仅仅是时间问题,而且时间不会太长。
Apache+PHP+FastCGI
对于目前的过渡阶段,很多开发者还是需要一个可以实现PHP4和PHP5共存的开发环境,这两天尝试在Windows下使用APACHE环境配置了一个PHP4和PHP5共存的环境,请注意:此配置使用 CGI 运行方式,而没有使用常见的 Apache modules 方式。我曾经尝试使用 Apache modules方式配置双PHP,但没有成功。
关键特性:
- Windows+Apache+PHP(Apache2.0下测试)
- PHP4+PHP5共存
- FastCGI
以下是配置中用到的Apache Conf:
# 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" AllowOverride None Options None Order allow,deny Allow from all Action php-script-4 "/php4/php.exe" ScriptAlias /php5/ "D:/server/php5/" Action php-script-5 "/php5/php-cgi.exe" AllowOverride None Options None Order allow,deny Allow from all fcgid-2.2-w32.zip AddHandler php-script-4 .php4 AddHandler php-script-5 .php5 #默认的使用的版本,可以在.htaccess文件中修改 AddHandler php-script-4 .php
简单说明下:PHP4和PHP5均使用手动安装包(不是Installer),分别解压到 d:\server\php4 和 d:\server\php5。使用AddType命令指定扩展名对应关系:PHP4使用扩展名 “php”,PHP5使用扩展名“php5”。AddType可以再 .httaccess文件中使用,以实现修改不同目录的默认PHP版本。
PHP4包解压后需要把dlls和sapi目录下的所有文件拷贝到PHP4的根目录,既和PHP.exe放在一起。php.ini文件直接放在PHP4/5的根目录中即可(d:\server\php4 和 d:\server\php5)。注意要确保系统其它位置不要出现php.ini文件,否则可能会覆盖有效的配置。PHP本身的配置我就不说了,自己查资料吧。
FastCGI
CGI方式运行PHP最大的缺点是效率低,可以配合Fast-cgi使用,Conf文件修改如下,增加最后3行即可。
除了FastCGI另外还有一个fcgid也可以是参考
# 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
相关PHP配置(可选的)
; ============================================================== ; 常用的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
参考资料
- 有关Fast CGI 请参阅:http://blogme.cn/node/6529 http://www.fastcgi.com/
- 有关Go PHP5 请参阅:http://www.ooso.net/index.php/archives/348
- 这里还有篇比较罗嗦的指南,也可以看看:http://www.seji.cn/tech/infoView/Article_122.html
- 最后还有最应该看的:PHP安装手册
!!!经反复测试APACHE2.2+fastCGI+PHP5.*在windows平台下运行存在问题,使用以上配置无法工作,使用Apache2.0一切正常!!!
相关错误提示(Apache’s errors.log)类似:
terminated with exit with status ’0′
FastCGI: incomplete headers (0 bytes) received from server
我的测试版本是:PHP5.2.6 / FastCGI 2.4.6-AP22.dll /Apache 2.2 / Windows2003表现为:
- 在不启用FastCGI时,PHP5的反应非常迟钝,特别是在加载了Mysql扩展之后,很奇怪的现象!!
- 启用FastCGI时不能正常工作,而PHP4配合相同的设定确工作的很好
相关的错误信息可以参看:
- FastCGI: server “D:/server/php5/php-cgi.exe” (pid 1708) terminated with exit with status ’0′
- (OS 109)管道已结束。 : FastCGI: comm with server “D:/server/php5/php-cgi.exe” aborted: GetOverlappedResult() failed
- FastCGI: incomplete headers (0 bytes) received from server “D:/server/php5/php-cgi.exe”

经测试发现在CGI环境下,APACHE无法正常支持HTTP方式的验证
似乎FastCGI的线程数(-processes n)过多会引发问题,即使看起来内存仍然有空余,我在某台服务器上启用 – processes 10时不能正常工作,改成4就可以了!
原因未知!
正找资料学习安装这个,感谢分享
还是有些隐患。我偷懒,直接安装VM Player,再安装一个Appliance。这样才放心使用开发环境。