Laravel – Enable SSL on MySQL/MariaDB Connections

By

in

,

Posted

Tags:

Updated

In database.php modify to have these lines, yours might not have it already included:

'sslmode' => env('DB_SSLMODE', 'prefer'),
'options' => extension_loaded('pdo_mysql') ? array_filter([
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA') !== null
? base_path(env('MYSQL_ATTR_SSL_CA'))
: env('MYSQL_ATTR_SSL_CA'),
]) : [],

Then, in .env you must add two additional keys:

MYSQL_ATTR_SSL_CA=ca.crt

Where this file is inside the current project directory, you can make this an absolute path by remove base_path() wrapping the env('MYSQL_ATTR_SSL_CA')

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *