如何通过SSL通过PHP连接到MySQL的亚马逊RDS实例 [英] How to connect to an Amazon MySQL RDS instance via PHP over SSL

查看:567
本文介绍了如何通过SSL通过PHP连接到MySQL的亚马逊RDS实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在运行一个Word preSS网站的EC2实例。在Word preSS分贝是一个RDS实例。我想连接到数据库通过SSL。

I have an EC2 instance running a WordPress site. The WordPress db is on a RDS instance. I want to connect to the db over SSL.

从我读过,那两个字preSS采用开箱即用的MySQL扩展不支持SSL。所以,我已经安装了一个字preSS分贝脚本使用库MySQLi,它不支持SSL。

From what I've read, the MySQL extension that WordPress uses out of the box doesn't support SSL. So, I've installed a WordPress db script that uses MySQLi, which does support SSL.

我遇到的问题是,亚马逊只提供一个密钥文件(<一href="http://docs.amazonwebservices.com/AmazonRDS/latest/UserGuide/index.html?Concepts.DBInstance.html#Concepts.DBEngine.MySQL51.SSLSupport"相对=nofollow>更多信息),和所有的例子我能找到使用的MySQLi通过SSL至少包括3个文件:

The problem I encountered is that Amazon only supplies one key file (more info), and all the examples I can find using MySQLi over SSL include at least 3 files:

$db = mysqli_init();
$db->ssl_set('server-key.pem','server-cert.pem','cacert.pem',NULL,NULL); 

我能够从mysql命令行应用程序连接到我的分贝超过SSL。谁能告诉我什么,我需要做的就是PHP的MySQLi扩展工作,因为我只有1个文件?

I'm able to connect to my db over SSL from the mysql command line app. Can anyone tell me what I need to do to get PHP's MySQLi extension to work, given that I only have the 1 file?

推荐答案

事实证明,这是比我想象的那么复杂。转动起来发现我的code,我还没有抓到一个错误的错误报告级别。使用ssl_set这样工作的:

Turns out this was less complicated than I thought. Turning up the error reporting level uncovered an error in my code that I hadn't caught. Using ssl_set this way works:

$db = mysqli_init();
$db->ssl_set(NULL,NULL,'/path/to/mysql-ssl-ca-cert.pem',NULL,NULL);
$db->real_connect($dbhost,$dbuser,$dbpassword,$dbname);

这篇关于如何通过SSL通过PHP连接到MySQL的亚马逊RDS实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆