我試圖將PHP mysqli連接設置爲兩個VPS服務器的MariaDB數據庫,並且需要加密通信,因爲它在公共網絡上。通過SSL的Mysql連接使用PHP mysqli
目前我可以通過命令行mysql客戶端正常連接從客戶端服務器到數據庫服務器,我通過tcpdump檢查連接是否加密。但由於某種原因,我無法弄清楚PHP部分。這是相對基本的nginx + php5-fpm + mariadb設置,但mysql正在使用非默認端口。 Debian的傑西,5.6.7的php5,MariaDB的10.0.16,nginx的1.6.2
這裏的測試腳本:
<?php
$DB_NAME = '';
$DB_HOST = '111.111.111.111';
$DB_USER = 'username';
$DB_PASS = 'password';
$mysqli = mysqli_init();
if (!$mysqli) {
die('mysqli_init failed');
}
//have tried witha and without the following with multiple variations
$mysqli->ssl_set(NULL, NULL, NULL,'/etc/mysql/ssl/',NULL);
if (!$mysqli->real_connect($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME, 11111, NULL,MYSQLI_CLIENT_SSL)) {
die('Connect Error (' . mysqli_connect_errno() . ') '
. mysqli_connect_error());
}
$query = "SHOW STATUS LIKE 'ssl_cipher'";
$result = $mysqli->query($query) or die($mysqli->error.__LINE__);
if($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
print_r($row);
}
}
else {
echo 'NO RESULTS';
}
mysqli_close($mysqli);
?>
主要錯誤我越來越沒有ssl_set:
2015/07/11 15:58:34 [error] 2857#0: *374 FastCGI sent in stderr: "PHP message: PHP Warning: mysqli::real_connect(): SSL operation failed with code 1. OpenSSL Error messages:
error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed in /srv/www/test.php on line 15
PHP message: PHP Warning: mysqli::real_connect(): Cannot connect to MySQL by using SSL in /srv/www/test.php on line 15
PHP message: PHP Warning: mysqli::real_connect(): [2002] (trying to connect via tcp://192.168.130.123:42139) in /srv/www/test.php on line 15
PHP message: PHP Warning: mysqli::real_connect(): (HY000/2002): in /srv/www/test.php on line 15".....
任何想法,將不勝感激。這真的讓我失望。
正確。然而,目前還有一個開放的bug,這顯然使得使用SSL和mysqlnd與自簽名證書無法使用SSL:https://bugs.php.net/bug.php?id = 68344 我想我現在要去autossh land。 ..至少應該工作。 – Tuxie