Configure Wordpress on Azure Cloud Service to connect to Azure MySQL over SSL Configure Wordpress on Azure Cloud Service to connect to Azure MySQL over SSL azure azure

Configure Wordpress on Azure Cloud Service to connect to Azure MySQL over SSL


Here is what I did:

  1. Obtain SSL certificate and save the certificate file to the root of my Wordpress project.

  2. Add the following into wp-config.php:

    define('DB_SSL', true);
  3. Add this to the function db_connect() in my wp-includes/wp-db.php. It must be called before mysqli_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.


This will solve the issue by adding these lines to wp_config.php

define(‘MYSQL_CLIENT_FLAGS’, MYSQLI_CLIENT_SSL);define(‘MYSQL_SSL_CA’, getenv(‘MYSQL_SSL_CA’));define(‘MYSQL_CLIENT_FLAGS’, MYSQLI_CLIENT_SSL | MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT );