How to connect to Amazon MySQL RAD instance via PHP over SSL

I have an EC2 instance running the WordPress site. WordPress db is in an instance of RDS. I want to connect to db via SSL.

From what I read, the MySQL extension used by WordPress out of the box does not support SSL. So, I installed a WordPress db script that uses MySQLi, which supports SSL.

The problem I ran into is that Amazon only supplies one key file ( more info ), and all the examples that 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 can connect to my db via SSL from mysql command line application. Can someone tell me what I need to do to get PHP MySQLi to work, given that I only have 1 file?

+3
source share
2 answers

Turns out it was less complicated than I thought. Turning on the error reporting level revealed an error in my code that I did not catch. Using ssl_set in 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);
+4
source

Try the following:

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

Source: https://habr.com/ru/post/1785530/


All Articles