有同样的问题。值得庆幸的是,其他一些人在这里提出了一个合理的解决方案:https://core.trac.wordpress.org/ticket/28625。端到端,这是我为使 SSL 工作所做的工作:
1.将以下内容添加到 wordpress wp-includes/wp-db.php 文件中。(除了最后两行仅用于插入点引用)
//ADDED per https://core.trac.wordpress.org/ticket/28625
// call set_ssl if mysql client flag set and settings available
if ( $client_flags & MYSQL_CLIENT_SSL ) {
$pack = array( $this->dbh );
$call_set = false;
foreach( array( 'MYSQL_SSL_KEY', 'MYSQL_SSL_CERT', 'MYSQL_SSL_CA',
'MYSQL_SSL_CAPATH', 'MYSQL_SSL_CIPHER' ) as $opt_key ) {
$pack[] = ( defined( $opt_key ) ) ? constant( $opt_key ) : null;
$call_set |= defined( $opt_key );
}
/* Now if anything was packed - unpack into the function.
* Note this doesn't check if paths exist, as per the PHP doc
* at http://www.php.net/manual/en/mysqli.ssl-set.php: "This
* function always returns TRUE value. If SSL setup is incorrect
* mysqli_real_connect() will return an error ..."
*/
if ( $call_set ) { // SSL added here!
call_user_func_array( 'mysqli_ssl_set', $pack );
}
}//END ADD - below is the point above which to insert this
if ( WP_DEBUG ) {
mysqli_real_connect( $this->dbh, $host, $this->dbuser, $this->dbpassword, null, $port, $socket, $client_flags );
2。自定义您的 wordpress wp-config.php 文件。
在您的 wp-config.php 文件中添加和自定义以下行。如果您有多个环境,您可以从开发/暂存以及生产中测试这些。
define('DB_HOST', 'rds-yourserver-abcdefghi9j.us-west-1.rds.amazonaws.com');
define('MYSQL_CLIENT_FLAGS', MYSQL_CLIENT_SSL);//This activates SSL mode
define('MYSQL_SSL_CA', '/file/path/to/your/aws/rds-combined-ca-bundle.pem');
请注意,您可以在配置中使用 5 个可用的 MYSQL_SSL* 设置,按照上面 #1 中的代码。我的 RDS 连接仅通过 _CA 选项通过 SSL 工作。
3.健全性测试您的连接是否已加密。
添加一个快速测试文件以显示当前的 Wordpress 连接是否使用 SSL。创建一个像这样的名为 test.php 的示例文件,并将其放入您的 wordpress 根目录或 Web 可访问的某个位置。完成测试后不要忘记删除此文件。
<?php
require( dirname( __FILE__ ) . '/wp-blog-header.php' ); //EDIT THIS PATH SO IT IS CORRECT FOR YOUR test.php file relative to the wp-blog-header.php file
global $wpdb;
$row = $wpdb->get_row( "SHOW STATUS LIKE 'Ssl_cipher'" );
var_dump($row);
/*
If you are connected over SSL this should output something like:
object(stdClass)#116 (2) { ["Variable_name"]=> string(10) "Ssl_cipher" ["Value"]=> string(10) "AES256-SHA" }
If you are NOT connected over SSL this should output something like:
object(stdClass)#116 (2) { ["Variable_name"]=> string(10) "Ssl_cipher" ["Value"]=> string(10) "" }
*/
?>
4.部署和测试您的连接
将您的更改和 test.php 文件部署到您的 wordpress 安装中,并根据需要重新启动您的 Web 服务器。我正在使用 apache,所以我运行
sudo apachectl restart