selinux 与 Can't connect to MySQL server

来源:互联网 发布:iphone降价规律 知乎 编辑:程序博客网 时间:2024/06/13 14:40
Warning: mysql_connect(): Can't connect to MySQL server on 'xxx'

在命令行使用php执行可以正常访问数据库,但是使用url访问apache却报错无法访问。

问题比较迷惑人,看起来似乎跟mysql,php,apache有关,其实与Selinux有关。。。

getenforce

setenforce 0 可以解决(参考:http://serverfault.com/questions/503489/cant-connect-to-mysql-server-13-using-php-function)

或者使用:

setsebool httpd_can_network_connect=1

来解决(参考自:http://stackoverflow.com/questions/4078205/php-cant-connect-to-mysql-with-error-13-but-command-line-can)

以后一定要多研究下selinux相关。。。

0 0
原创粉丝点击