你看到的这个文章来自于http://www.cnblogs.com/ayanmwphp
php代码很简单:mysql
$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 能够查看运行结果,可是 在个人windows浏览器下报错:linux
Could not connect: Can't connect to MySQL server on '127.0.0.1' (13) 2003sql
缘由:
#getsebool -a | grep httpd
[neo@neo phpMyTest]$ getsebool -a | grep httpdwindows
发现 httpd_can_network_connect --> off
解决方案:
#setsebool httpd_can_network_connect 1浏览器
原来是 SELINUX,因此我通常直接关闭SELINUX和 iptables ip6tablesspa
# 关闭SELINUX chkconfig --level 12345 iptables off chkconfig --level 12345 ip6tables off service iptables stop service ip6tables stop 查看SELinux状态: 一、/usr/sbin/sestatus -v ##若是SELinux status参数为enabled即为开启状态 SELinux status: enabled 二、getenforce ##也能够用这个命令检查 关闭SELinux: 一、临时关闭(不用重启机器): setenforce 0 ##设置SELinux 成为permissive模式 ##setenforce 1 设置SELinux 成为enforcing模式 二、修改配置文件须要重启机器: 修改/etc/selinux/config 文件 将SELINUX=enforcing改成SELINUX=disabled