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

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

问题描述

我有一个运行 WordPress 站点的 EC2 实例.WordPress 数据库位于 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.

据我所知,WordPress 开箱即用的 MySQL 扩展不支持 SSL.所以,我安装了一个使用 MySQLi 的 WordPress db 脚本,它支持 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.

我遇到的问题是亚马逊只提供一个密钥文件(更多信息),我能找到的所有通过 SSL 使用 MySQLi 的示例都至少包含 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 连接到我的数据库.鉴于我只有 1 个文件,谁能告诉我我需要做什么才能使 PHP 的 MySQLi 扩展工作?

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?

推荐答案

事实证明这没有我想象的那么复杂.调高错误报告级别会发现我的代码中有一个我没有发现的错误.以这种方式使用 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);

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

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