连接脚本:
$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/