selinux 與 Can't connect to MySQL server

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相關。。。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章