windows下apache2+fastcgi+php
URL:http://blog.iyi.cn/start/2006/12/windowsapache2fastcgiphp.html
为了测试一下php在各种环境下的运行速度,搞明白fastcgi的运行机制和配置,晚上在笔记本上配置了一下apache2+fastcgi+php。
虽然网上很多资料,官方也有资料,但是因为目录结构不同,我配置了几次都没能成功。这次仔细的一点一点地配置,总算弄明白了。
官方的文档是这样写的:
FastCgiServer /export/httpd/cgi-bin/php AddHandler php-fastcgi .php <显然是Unix上的配置,我的php装在d:/server/php/ 所以简单的将/export/httpd/cgi-bin/php改为d:/server/php/php-cgi.exe 结果总是不能访问网站。 经过反复测试,最后明白,为什么上面写的是/cgi-bin/php原来cgi的方式执行php脚本实际上是将php-cgi.exe作为一个cgi进程,所以php-cgi.exe所在的目录必须有cgi执行权限,然后将所有的名为.php的请求转发给php-cgi.exe进程;普通的cgi脚本,例如perl大概是根据头上那句#!d:/server/perl/bin/perl.exe -w来启动perl,所以不需要将perl放进cgi-bin目录。类似于fastcgi官方的用shell配置php+fastcgi的写法:> SetHandler fastcgi-script < > Action php-fastcgi /cgi-bin/php DirectoryIndex index.html index.shtml index.cgi index.php AddType application/x-httpd-php .php
#!/bin/shPHPRC="/usr/local/etc/php/client"
export PHPRC
PHP_FCGI_CHILDREN=4
export PHP_FCGI_CHILDREN
exec /usr/local/bin/php-fcgi
所以配置的时候,要将php-cgi.exe所在的路径设置加上ExecCGI下面,或者用ScriptAlias。
修改后的配置文件为:
FastCgiServer d:/server/php/php-cgi.exe
AddHandler php-fastcgi .php
ScriptAlias /php/ "d:/server/php/"
Action php-fastcgi /php/php-cgi.exe
AddType application/x-httpd-php .php
出现这个问题,主要是因为对cgi的运行方式了解不够,文中错漏之处,请指正。
还没有进行压力测试,只是简单看了一下discuz论坛的执行时间,用fastcgi和php5_module没有明显差别。
fcgid的配置相对简单,从http://www.apachelounge.com/下载相应的fcgid binary for windows,解压到apache modules目录,根据fcgid官网的配置文档配置apache就可以了。
配置完后,php可以运行,但是运行discuz的时候不能连接数据库,不知道什么问题:
Discuz! info: Can not connect to MySQL serverTime: 2006-12-22 12:09am
Script: /index.php
Error: Can't create TCP/IP socket (10106)
Errno.: 2004
Similar error report has beed dispatched to administrator before.
似乎是我改了discuz的某个地方,导致这个错误,因为unix的discuz在fcgid上运行的很好。
评论:
我就是mod_fcgid的作者:) mod_fcgi官网的文档:
Note: If you get:
Can't create TCP/IP socket (10106) error while running PHP script(on Win32 only), you will have to set these(Please modify the values if necessary):
DefaultInitEnv PHPRC "c:/php/"
DefaultInitEnv PATH "c:/php;C:/WINDOWS/system32;C:/WINDOWS;C:/WINDOWS/System32/Wbem;"
DefaultInitEnv SystemRoot "C:/Windows"
DefaultInitEnv SystemDrive "C:"
DefaultInitEnv TEMP "C:/WINDOWS/TEMP"
DefaultInitEnv TMP "C:/WINDOWS/TEMP"
DefaultInitEnv windir "C:/WINDOWS"
(Thank Steffen of apachelounge.com for this note)
by: pqf | January 8, 2007 9:40 AM
收到作者的回复,倍感荣幸。
稍后作测试。
by: david | January 8, 2007 12:11 PM