欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

CentOS下php使用127.0.0.1不能連接mysql的解決方法

 更新時間:2015年01月26日 10:58:42   投稿:junjie  
這篇文章主要介紹了CentOS下php使用127.0.0.1不能連接mysql的解決方法,本文原因是SELINUX導(dǎo)致的連接失敗,需要的朋友可以參考下

php代碼很簡單:

復(fù)制代碼 代碼如下:

$server="127.0.0.1";
println("Begin");
$link = mysql_connect($server,"mysql","mysql");
if (!$link) {
    die('Could not connect: ' . mysql_error().mysql_errno());
}

linux本機下使用php mysql.php 可以查看運行結(jié)果,但是 在我的windows瀏覽器下報錯:

復(fù)制代碼 代碼如下:

Could not connect: Can't connect to MySQL server on '127.0.0.1' (13) 2003

原因:

復(fù)制代碼 代碼如下:

#getsebool -a | grep httpd
[neo@neo phpMyTest]$ getsebool -a | grep httpd

發(fā)現(xiàn) httpd_can_network_connect --> off
解決方案:
復(fù)制代碼 代碼如下:

#setsebool httpd_can_network_connect 1

原來是 SELINUX,所以我一般直接關(guān)閉SELINUX和 iptables ip6tables

復(fù)制代碼 代碼如下:

# 關(guān)閉SELINUX
chkconfig --level 12345 iptables off

chkconfig --level 12345 ip6tables off

service iptables stop

service ip6tables stop


查看SELinux狀態(tài):

1、/usr/sbin/sestatus -v      ##如果SELinux status參數(shù)為enabled即為開啟狀態(tài)

SELinux status:                 enabled

2、getenforce                 ##也可以用這個命令檢查

關(guān)閉SELinux:

1、臨時關(guān)閉(不用重啟機器):

setenforce 0                  ##設(shè)置SELinux 成為permissive模式

                              ##setenforce 1 設(shè)置SELinux 成為enforcing模式

2、修改配置文件需要重啟機器:

修改/etc/selinux/config 文件

將SELINUX=enforcing改為SELINUX=disabled

相關(guān)文章

最新評論