wordpress: MySQL connection uses SSL encryption
Not always you have a www server (Apache) and database (MySQL) on same machine. If not, it’s good to use SSL during the database connection. The hosting provider have to support MySQL connection over SSL. See MySQL reference for details.
To the WordPress 3.0.1 we need to add to the wp-config.php a line:
define('DB_SSL', true);
and patch the wp-db.php file wich is located in the wp-includes directory.
$ svn diff ./wp-includes/wp-db.php
Index: wp-includes/wp-db.php
===================================================================
--- wp-includes/wp-db.php (wersja 15639)
+++ wp-includes/wp-db.php (kopia robocza)
@@ -1025,9 +1025,13 @@
*/
function db_connect() {
global $db_list, $global_db_list;
+
+ if(defined('DB_SSL') && DB_SSL === true ){
+ $this->dbh = @mysql_connect( $this->dbhost, $this->dbuser, $this->dbpassword, true , MYSQL_CLIENT_SSL);
+ }else{
+ $this->dbh = @mysql_connect( $this->dbhost, $this->dbuser, $this->dbpassword, true );
+ }
- $this->dbh = @mysql_connect( $this->dbhost, $this->dbuser, $this->dbpassword, true );
-
if ( !$this->dbh ) {
$this->bail( sprintf( /*WP_I18N_DB_CONN_ERROR*/"
<h1>Error establishing a database connection</h1>
That’s all :)