首页 > 代码库 > Windows中APACHE开启fastcgi后无法连接数据库
Windows中APACHE开启fastcgi后无法连接数据库
环境:
Windows server 2003 x64
Apache 2.2.14
mod_fcgid-2.2b-w32.zip
PHP VC9 x86 Non Thread Safe(用Visual C++ 2008 Redistributable Package x86来编译的)
我用下面的配置能使FASTCGI启动:
LoadModule fcgid_module modules/mod_fcgid.so
<Directory "C:/www">
AllowOverride None
Order allow,deny
Options FollowSymLinks ExecCGI
AddHandler fcgid-script .php
FCGIWrapper "c:/php/php-cgi.exe" .php
Allow from all
</Directory>
<IfModule mod_fcgid.c>
IPCCommTimeout 40
IPCConnectTimeout 10
MaxProcessCount 8
OutputBufferSize 64
ProcessLifeTime 240
MaxRequestsPerProcess 500
</IfModule>
但会发生下面的一些错误:
1、echo gethostbyname(‘google.com‘);
上面只会返回"google.com"而不是正常返回的IP。
2、$connection1=mysql_connect("localhost",‘root‘,‘password‘);
上面这个会报错 mysql_connect(): php_network_getaddresses: getaddrinfo failed: No such host is known. in C:/www/test.php on line 11
这是因为FASTCGI未取到环境变量的原因,解决办法是在Apache配置文件增加如下语句:
DefaultInitEnv PATH "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"
Windows中APACHE开启fastcgi后无法连接数据库