Nota: Este artigo foi publicado originalmente em 2013. Alguns passos, comandos ou versões de software podem ter mudado. Consulte a documentação atual de WordPress para as informações mais recentes.

In this step-by-step guide, you’ll learn connect to a mysql server using ssl from a wordpress site. WordPress is the world’s most popular content management system (CMS), powering over 40% of all websites on the internet.

Pré-requisitos

Antes de começar, certifique-se de ter:

  • WordPress installation (self-hosted)
  • Administrator access to WordPress dashboard
  • FTP/SFTP or file manager access to server files

How to: Connect to a (http://www.mysql.com “MySQL”) using (http://en.wikipedia.org/wiki/Transport_Layer_Security “Transport Layer Security”) from a (http://wordpress.org “WordPress”) Site

Truly you could title this post simply How to Connect to a MySql server using SSL from a (http://www.php.net “PHP”) application. The key is in the connection construct, which by default in Wordpress it looks sort of like this:

$this->dbh = mysql_connect( $this->dbhost, $this->dbuser, $this->dbpassword, $new_link, $client_flags );

So here comes the key to the whole business: You must use the “MYSQL_CLIENT_SSL ” client flag to indicate PHP to use SSL. So, in the case of WordPress you could manually open the db.php file and make the manual edit or rely on the parameter $client_flags which is defined as follows:

$client_flags = defined( 'MYSQL_CLIENT_FLAGS' ) ? MYSQL_CLIENT_FLAGS : 0;

So what this means for you is that by defining MYSQL_CLIENT_FLAGS in something like your wp-config.php file you could set the flag to MYSQL_CLIENT_SSL effectively indicating PHP to connect to MySql via SSL. Below is a sample of what to add to your config file:

define(‘MYSQL_CLIENT_FLAGS’, MYSQL_CLIENT_SSL);

Hope this helps!

Resumo

You’ve successfully learned connect to a mysql server using ssl from a wordpress site. If you run into any issues, double-check the prerequisites and ensure your WordPress environment is properly configured.

Artigos Relacionados