- 客户端系统:CentOS Linux release 7.0.1406 (Core)
- 客户端IP:222.222.222.222
http://test.com 指向IP地址222.222.222.222
服务器系统:Gentoo Base System release 1.12.13
- 服务器IP:111.111.111.111
连接脚本:
$connection = new \mysqli('111.111.111.111', 'user', 'password', 'db');
if (mysqli_connect_error()) {
echo "Error: {$connection->connect_error}";
}
else {
echo "Server Info: {$connection->server_info}";
}
当我试图在浏览器中打开“http://test.com/test.php”时,我遇到了以下问题:
Error: Can't connect to MySQL server on '111.111.111.111' (13)
...但是当我在服务器222.222.222.222上从命令行启动此脚本时,我得到了另一个结果:
/usr/bin/php /var/www/reporter/test.php
Server Info: 5.5.14-enterprise-commercial-advanced-log
命令行直接连接也是正确的:
mysql -h 111.111.111.111 -u user -p -P 3306
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MySQL connection id is 25236357
Server version: 5.5.14-enterprise-commercial-advanced-log MySQL Enterprise Server - Advanced Edition (Commercial)
Copyright (c) 2000, 2014, Oracle, Monty Program Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
答案
客户环境问题 - Centos中的Selinux。修复命令:
setsebool -P httpd_can_network_connect=1
new \mysqli('111.11
? - Jay Blanchard