- 客户端系统: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
- 服务器地址: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
最佳答案
客户端环境问题 - Centos 中的 Selinux。 修复它的命令:
setsebool -P httpd_can_network_connect=1
关于php - 无法从 php 连接到远程 Mysql 服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27107881/