Configure Wordpress on Azure Cloud Service to connect to Azure MySQL over SSL
Here is what I did:
Obtain SSL certificate and save the certificate file to the root of my Wordpress project.
Add the following into
wp-config.php
:define('DB_SSL', true);
Add this to the function
db_connect()
in mywp-includes/wp-db.php
. It must be called beforemysqli_real_connect()
:// Just add this linemysqli_ssl_set($this->dbh, NULL, NULL, ABSPATH . 'BaltimoreCyberTrustRoot.crt.pem', NULL, NULL); if ( WP_DEBUG ) { mysqli_real_connect( $this->dbh, $host, $this->dbuser, $this->dbpassword, null, $port, $socket, $client_flags );} else { @mysqli_real_connect( $this->dbh, $host, $this->dbuser, $this->dbpassword, null, $port, $socket, $client_flags );}
The solution seems a bit dirty but it works for me.
I found the solution to be much simpler when using an Azure mySQL database server in conjunction with a Wordpress container image. If you're using a VPS this may not apply.
- Download the BaltimoreCyberTrustRoot.crt.pem referenced here: https://docs.microsoft.com/en-us/azure/mysql/howto-configure-ssl
- Place the file in the root of your Wordpress install
- Add these two variables in wp-config:
define( 'MYSQL_CLIENT_FLAGS', MYSQLI_CLIENT_SSL );
define('MYSQL_SSL_CA_PATH','/');