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
以後一定要多研究下selinux相關。。。