1
- 客戶端系統:CentOS的Linux的發佈7.0.1406(核心)
- 客戶端IP:222.222.222.222
http://test.com看起來到IP 222.222.222.222無法從PHP連接到遠程MySQL服務器
服務器系統:Gentoo基本系統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.
回答
問題與客戶端的環境 - SELINUX於CentOS。命令fo修復它:
setsebool -P httpd_can_network_connect=1
檢查的東西,如防火牆,了Suhosin/SELinux的百般阻撓的事,等等等等。 – 2014-11-24 15:11:14
很確定錯誤13是一個權限的事情。仔細檢查PHP中的密碼以確保? – rjdown 2014-11-24 15:13:57
爲什麼你在這一行有一個反斜槓 - 'new \ mysqli('111.11'? – 2014-11-24 15:14:05