Laravel, MySQL, Azure, SSL Connection is required

Viewed 559

I'm trying to deploy a laravel 5.8 application to Azure, but I'm getting the following error;

"SSL connection is required. Please specify SSL options and retry."

In the config folder there wasn't a database.php file, so I created one using the database.php in the Laravel Git Repository. I downloaded the BaltimoreCyberTrustRoo.crt.pem file from MS and placed this inside the root of my application inside a folder called ssl. I've then modified the database.php file to this;

'mysql' => [
            'driver' => 'mysql',
            'url' => env('DATABASE_URL'),
            'host' => env('DB_HOST', '127.0.0.1'),
            'port' => env('DB_PORT', '3306'),
            'database' => env('DB_DATABASE', 'forge'),
            'username' => env('DB_USERNAME', 'forge'),
            'password' => env('DB_PASSWORD', ''),
            'unix_socket' => env('DB_SOCKET', ''),
            'charset' => 'utf8mb4',
            'collation' => 'utf8mb4_unicode_ci',
            'prefix' => '',
            'prefix_indexes' => true,
            'strict' => true,
            'engine' => null,
            'sslmode' => env('DB_SSLMODE', 'prefer'),
            'options' => (env('MYSQL_SSL') && extension_loaded('pdo_mysql')) ? [
                PDO::MYSQL_ATTR_SSL_KEY    => base_path('ssl/BaltimoreCyberTrustRoot.crt.pem'),
            ] : []
        ],

However, even with this change, I'm still seeing the same error.

I've attached a screenshot of the folder structure incase it is useful.

enter image description here

2 Answers

I managed to resolve this by changing the mysql options value to;

'options' => [
                PDO::MYSQL_ATTR_SSL_KEY    => base_path('ssl/BaltimoreCyberTrustRoot.crt.pem'),
        ]

instead of

'options' => (env('MYSQL_SSL') && extension_loaded('pdo_mysql')) ? [
                PDO::MYSQL_ATTR_SSL_KEY    => base_path('ssl/BaltimoreCyberTrustRoot.crt.pem'),
            ] : []

Mine is a non production(just learning) scenario, so I disabled ssl.

MySql on Azure SSL disabled

enter image description here

If it is enabled, I am getting this error.

MySql on Azure SSL Enabled

Related