最近在centos 下 编译安装 nginx + php5.4 ,其中,mysql 通过yum 安装,后连接数据库错误
$id=mysql_connect("localhost","root","123456")or die(mysql_error());Fatal error: No such file or directory in /usr/local/nginx/html/
解决办法:打开php的error_log,观察错误日志
1. 修改php-fpm.conf中配置 没有则增加
catch_workers_output = yes
error_log = log/error_log
2. 修改php.ini中配置,没有则增加
log_errors = On
error_log = "/usr/local/lnmp/php/var/log/error.log"
error_reporting=E_ALL&~E_NOTICE
3. 重启php-fpm
查看php 的error.log 报错信息如下:
[12-May-2014 16:38:22] WARNING: [pool www] child 6961 said into stderr: "NOTICE: PHP message: PHP Fatal error: No such file or directory in /usr/local/nginx/html/connections/conn.php on line 6"
[12-May-2014 16:40:08] WARNING: [pool www] child 6962 said into stderr: "NOTICE: PHP message: PHP Warning: mysql_connect(): No such file or directory in /usr/local/nginx/html/test.php on line 2"
但实际上文件是存在的,文件的第二行内容如下:
$id=mysql_connect("localhost","root","123456")or die(mysql_error());
查看mysql.sock文件的位置
root@node1:/var/mysql# vim /usr/local/mysql/my.cnf
socket = /usr/local/mysql/data/mysql.sock
root@node1:~# cd /var/
root@node1:/var# mkdir mysql
root@node1:/var# chmod 755 mysql
root@node1:~# cd /var/mysql/
root@node1:/var/mysql# ln -s /usr/local/mysql/data/mysql.sock mysql.sock
root@node1:/var/mysql# cd /tmp/
root@node1:/tmp# ln -s /usr/local/mysql/data/mysql.sock mysql.sock
显示结果正常: