You need to remove php-mysql and install php-mysqlnd. On Centos:
sudo yum remove php-mysql sudo yum install php-mysqlnd sudo yum reboot
Ubuntu / Debian
sudo apt-get remove php5-mysql sudo apt-get install php5-mysqlnd sudo reboot
mysqli procedural:
$con=mysqli_init(); if (!$con) { die("mysqli_init failed"); } mysqli_ssl_set($con,'/ssl/client-key.pem','/ssl/client-cert.pem', '/ssl/ca.pem',NULL,NULL); if (!mysqli_real_connect($con,'xx.xxx.xxx.xxx', 'user', 'pass' ,'dbname')) { die("Connect Error: " . mysqli_connect_error()); } mysqli_close($con); ?>
PDO
$ssl = array( PDO::MYSQL_ATTR_SSL_KEY =>'/ssl/client-key.pem', PDO::MYSQL_ATTR_SSL_CERT=>'/ssl/client-cert.pem', PDO::MYSQL_ATTR_SSL_CA =>'/ssl/ca.pem' ); try { $dbl = new PDO("mysql:host=$host;dbname=$database", $user, $password, $ssl); $dbl->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch(PDOException $e) { echo $e->getMessage(); die; }
Your certification paths must be correct. Try this in your SSL to make sure the files:
if(file_exists('/ssl/client-key.pem') && file_exists('/ssl/client-cert.pem') && file_exists('/ssl/ca.pem')) echo 'file exists';
The remote host (database server) must also have SSL enabled. Run request
SHOW VARIABLES LIKE '%ssl%';
OUTPUT:
+---------------+----------------------+ | Variable_name | Value | +---------------+----------------------+ | have_openssl | YES | | have_ssl | YES | | ssl_ca | /ssl/ca.pem | | ssl_capath | | | ssl_cert | /ssl/server-cert.pem | | ssl_cipher | DHE-RSA-AES256-SHA | | ssl_key | /ssl/server-key.pem | +---------------+----------------------+
If it is disabled, it will not work. Your /etc/my.cnf (or where your my.cnf is located) should contain:
ssl-ca=/ssl/ca.pem ssl-cert=/ssl/server-cert.pem ssl-key=/ssl/server-key.pem ssl-cipher=DHE-RSA-AES256-SHA
MySQL Resource for generating keys: http://dev.mysql.com/doc/refman/5.0/en/creating-ssl-files-using-openssl.html
Finally, the DHE cipher is no longer considered secure. The ciphers are constantly breaking, so you will need to find out which are considered safe today.