Back

Connecting MySQL over SSL


mfsi-subhranil posted 5 years ago

How i connect MySQL using SSL. How I can configure it in databse.php ?

I added all my .pem files along with connection parameter like by following http://laravelsnippets.com/snippets/add-pdo-ssl-options-to-database-connection-config

'mysql' => array(
		'driver'    => 'mysql',
		'host'      => 'localhost',
		'database'  => 'testDB',
		'username'  => 'root',
		'password'  => 'testPWD',
		'charset'   => 'utf8',
		'collation' => 'utf8_unicode_ci',
		'prefix'    => '',
                    'options'   => array(
                            PDO::MYSQL_ATTR_SSL_KEY    => '/var/www/cert/client-key.pem',
			PDO::MYSQL_ATTR_SSL_CERT    => '/var/www/cert/client-cert.pem',
			PDO::MYSQL_ATTR_SSL_CA    => '/var/www/cert/ca-cert.pem'                
                   ),
	),

After this i run SHOW STATUS LIKE 'Ssl_cipher' query which returns empty value for Ssl_cipher.

But if i do it with core PHP like

$db = mysqli_init();
mysqli_options ($db, MYSQLI_OPT_SSL_VERIFY_SERVER_CERT, true);

$db->ssl_set('/var/www/cert/client-key.pem', '/var/www/cert/client-cert.pem', '/var/www/cert/ca-cert.pem', NULL, NULL);

$link = mysqli_real_connect ($db, 'localhost', 'root', 'testPWD', 'testDB', 3306, NULL, MYSQLI_CLIENT_SSL);

It works and return value for Ssl_cipher.

Thanks, Subhranil

mfsi-subhranil replied 5 years ago Solution

I able to figure it out. Its working now. My certificate folder had an permission issue.

Thanks, Subhranil


Sign in to participate in this thread!



We'd like to thank these amazing companies for supporting us