简体   繁体   中英

How to connect to an Amazon MySQL RDS instance via PHP over 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.

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.

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); 

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?

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);

Try this:

$db = mysqli_init();
$db->ssl_set(null, 'https://rds.amazonaws.com/doc/mysql-ssl-ca-cert.pem', null, null, null);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM