I've been searching all over the internet and haven't had any success.
I'm trying to connect to an azure mysql database over ssl from my laravel application.
I've confirmed I can connect to the database if I turn ssl off. So the settings are correct. What trips me up, and what I can find no documentation on is how to connect via ssl. I've got a sslkey - which I've confirmed can be used to to connect to the database with one of my database management programs - so the pieces are there.
Laravel, however, seems to be failing.
Here's my database driver:
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
'engine' => null,
'sslmode' => env('DB_SSLMODE', 'prefer'),
'options' => array(
PDO::MYSQL_ATTR_SSL_KEY => '\ssl\DatabaseCACert.pem'),
],
What am I missing? The database is just refusing the connection at the moment. SQLSTATE[HY000] [2002] So it's close.
解决方案
You need to provide the full path to the files. If they're in your laravel application folder then you can use the base_path method to generate the full poth. You may also need to define the cert and ca.
'options' => [
PDO::MYSQL_ATTR_SSL_KEY => base_path('ssl/client-key.pem'),
PDO::MYSQL_ATTR_SSL_CERT => base_path('ssl/client-cert.pem'),
PDO::MYSQL_ATTR_SSL_CA => base_path('ssl/ca-cert.pem')
]