php代碼很簡單:
$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瀏覽器下報錯:
Could not connect: Can't connect to MySQL server on '127.0.0.1' (13) 2003
原因:
#getsebool -a | grep httpd
[neo@neo phpMyTest]$ getsebool -a | grep httpd
發現 httpd_can_network_connect --> off
解決方案:
#setsebool httpd_can_network_connect 1
原來是 SELINUX,所以我一般直接關閉SELINUX和 iptables ip6tables
# 關閉SELINUX chkconfig --level 12345 iptables off chkconfig --level 12345 ip6tables off service iptables stop service ip6tables stop 查看SELinux狀態: 1、/usr/sbin/sestatus -v ##如果SELinux status參數為enabled即為開啟狀態 SELinux status: enabled 2、getenforce ##也可以用這個命令檢查 關閉SELinux: 1、臨時關閉(不用重啟機器): setenforce 0 ##設置SELinux 成為permissive模式 ##setenforce 1 設置SELinux 成為enforcing模式 2、修改配置文件需要重啟機器: 修改/etc/selinux/config 文件 將SELINUX=enforcing改為SELINUX=disabled
參考資料:
http://hi.baidu.com/zwfec/item/64ef5ed9bf1cb3feca0c397c
順便再道一下:
CentOS下 無法ping外網IP
centos DNS 不能解析 裝好centos時發現yum install vim時無法安裝。原來DNS不能解析 配置vi /etc/resolv.conf 發現重啟就沒了。 最終解決 修改 vi /etc/sysconfig/network-scripts/ifcfg-Auto_eth0 添加 DNS1=8.8.8.8 DNS2=8.8.4.4 DNS3=192.168.1.1 重啟網絡 生成resolv.conf 配置 service network restart ------------- [root@localhost langxw]# ping 8.8.8.8 connect: 網絡不可達 。原來沒有下面的GATEWAY=192.168.1.1 TYPE=Ethernet BOOTPROTO=none IPADDR=192.168.1.121 PREFIX=24 GATEWAY=192.168.1.1 DEFROUTE=yes