我有一个关于用CakePHP 3通过SSL连接到mySQL的问题,我知道这可能更多的是一个PHP问题,但我只是在这里编写了我使用的框架。
因此,我设置了一个远程mysql服务器,并希望将CakePHP与它连接起来。不幸的是,我得到了MySQL错误:
SQLSTATE[HY000] [3159] Connections using insecure transport are prohibited while --require_secure_transport=ON. 因为我配置服务器只允许安全连接。之后,我搜索了有关安全连接的Cakephp文档,并找到了ssl证书。这是我的装置:
config.php
'Datasources' => [
'default' => [
'className' => 'Cake\Database\Connection',
'driver' => 'Cake\Database\Driver\Mysql',
'persistent' => false,
'host' => 'remote-ip',
/**
* CakePHP will use the default DB port based on the driver selected
* MySQL on MAMP uses port 8889, MAMP users will want to uncomment
* the following line and set the port accordingly
*/
//'port' => 'non_standard_port_number',
'username' => 'my_user',
'password' => 'my_password',
'database' => 'my_database',
'encoding' => 'utf8',
'timezone' => 'UTC',
'flags' => [],
'cacheMetadata' => true,
'ssl_key' => '/home/my-user/client-ssl/client-key.pem',
'ssl_cert' => '/home/my-user/client-ssl/client-cert.pem',
'ssl_ca' => '/home/my-user/client-ssl/ca.pem',
'log' => false,不幸的是,我刚刚得到了以下错误:
SQLSTATE[HY000] [2002]据我所知,应该使用证书正确地设置所有内容,因为我可以使用终端和续集登录证书,如下所示:
mysql -u my_user -h remote_ip -p --ssl-ca=~/client-ssl/ca.pem --ssl-cert=~/client-ssl/client-cert.pem --ssl-key=~/client-ssl/client-key.pem如果我尝试这样的原始php (当然是用我的信息):
<?php
ini_set ('error_reporting', E_ALL);
ini_set ('display_errors', '1');
error_reporting (E_ALL|E_STRICT);
$db = mysqli_init();
mysqli_options ($db, MYSQLI_OPT_SSL_VERIFY_SERVER_CERT, true);
$db->ssl_set('/etc/mysql/ssl/client-key.pem', '/etc/mysql/ssl/client-cert.pem', '/etc/mysql/ssl/ca-cert.pem', NULL, NULL);
$link = mysqli_real_connect ($db, 'ip', 'user', 'pass', 'db', 3306, NULL, MYSQLI_CLIENT_SSL);
if (!$link)
{
die ('Connect error (' . mysqli_connect_errno() . '): ' . mysqli_connect_error() . "\n");
} else {
$res = $db->query('SHOW TABLES;');
print_r ($res);
$db->close();
}
?>我得到了:
PHP警告: mysqli_real_connect():对等证书CN=
MySQL_Server_5.7.20_Auto_Generated_Server_Certificate' did not match expected CN=remote_ip‘
所以我现在的问题是。是否有人有类似的问题,或可以帮助我的证书?(我使用ubuntu16,php 7)或者有其他方法来解决“使用不安全传输的连接.”-error?
发布于 2017-12-27 16:17:17
该错误(Peer certificate CN=...)告诉您的是,自动生成的证书是为IP或域名创建的(可能是127.0.0.1?)而不是和你有联系的那个。确保您有一个证书,无论'remote-ip'是什么。
很可能,host条目在config.php中是不正确的。尝试将其设置为您的域名、服务器-ip,甚至是“localhost”。
'host' => 'remote-ip',生成一个证书.
还可能遇到另一个已经解决的问题:
https://stackoverflow.com/questions/47995069
复制相似问题