I configured PHP to use Apache mod_fcgid. PHP is working, but after changes in configuration I am not able to connect to MySQL via PHP. How to fix this?
To check MySQL connection I use the following PHP code:
error_reporting(E_ALL);
$link = mysql_connect('127.0.0.1', 'root', 'password_here');
if (!$link) {
die('Could not connect. Error message: <' . mysql_error() . '>');
}
echo 'Connected successfully';
Error message returned by mysql_error()
is empty.
I use the following configuration in Apache:
LoadModule fcgid_module modules/mod_fcgid.so
<IfModule fcgid_module>
AddHandler fcgid-script .fcgi .php
DefaultInitEnv PHPRC "C:/Program Files/php5"
DefaultInitEnv PHP_FCGI_MAX_REQUESTS 1000
MaxRequestsPerProcess 1000
MaxProcessCount 15
IPCCommTimeout 120
IdleTimeout 120
FCGIWrapper "C:/PROGRA~1/php5/php-cgi.exe" .php
AddType application/x-httpd-php .php
DefaultInitEnv PATH "C:/PROGRA~1/MYSQL/MYSQLS~1.0/LIB/OPT;C:/PROGRA~1/APACHE~1/APACHE2.2/BIN;C:/WINDOWS/system32;C:/WINDOWS"
</IfModule>
PHP 5.3.1, Apache/2.2.14开发者_如何学编程 (Win32), MySQL 5.0.67-community-nt, Windows Vista Home Premium Service Pack 1. I downloaded binaries of mod_fcgid from http://www.apachelounge.com/download/mods/mod_fcgid-2.2b-w32.zip
EDIT:
I used phpinfo()
to compare configuration. "Loaded Configuration File
" is the same for both with and without mod_fcgid
. mysql
section is the same for both configs. What I found out that Environment section when mod_fcgid is turned on contains only FastCGI related variable (4 items only), while without mod_fcgid - much more.
EDIT:
I obtain the following warning:
Warning: mysql_connect() [function.mysql-connect]: in E:\ ... \testphp\mysql.php on line 7
EDIT
Error log of mysql contain no any errors on mysql_connect()
.
Are you sure that Warning: mysql_connect() [function.mysql-connect]: in E:\ ... \testphp\mysql.php on line 7
is the full error ? Because that's unusual it should say what's wrong there.
Also please check your mysql server's log file for any anomalies and post them here. mysql error log documentation.
Have you tried running php_info()
to see if the mysql module is present and configured for your CGI? The ini
configuration can be different between CGI and other method of launching.
Got the same problem and solved it this way:
- Edit your php.ini file of cgi version (vi /etc/php5/cgi/php.ini)
- Add the following line: extension=mysql.so
- Restart your Apache (
service apache2 reload
AND/etc/init.d/apache3 restart
)
精彩评论