MySQL with SSL returns bad gateway

Posted 7 months ago by bcharron

I am trying to connect to a SSL enabled database with a Laravel application, but when I do so, I get a bad gateway error. Per a few different resources, I found the following configuration for the MySQL driver to add support for SSL connections, but with this driver configuration, I get the Bad Gateway error.


'mysql' => [
            'driver' => 'mysql',
            'host' => env('DB_HOST', ''),
            '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' => '',
            'sslmode' => env('DB_SSLMODE', 'prefer'),
            'options'   => [
                PDO::MYSQL_ATTR_SSL_CA    => '/path/to/file/ca.pem',
                PDO::MYSQL_ATTR_SSL_CERT    => '/path/to/file/client-cert.pem',
                PDO::MYSQL_ATTR_SSL_KEY    => '/path/to/file/client-key.pem'
            'strict' => true,
            'engine' => null,

I am using Laravel Valet as the development environment for this. I get the following error in the Valet NGINX error log: 2018/06/14 07:51:50 [error] 6495#0: *15 upstream prematurely closed connection while reading response header from upstream, client:, server:, request: "POST /oauth/token HTTP/1.1"

Does anyone know how to resolve this issue with a SSL enabled DB connection in a Laravel application or on Valet?

Please sign in or create an account to participate in this conversation.

Laracasts Mascot

Hi, Have We Met Yet?

Did you know that, in addition to the forum, Laracasts includes well over 1000 lessons on modern web development? All for the price of one lunch out per month.

Sign Me Up


Reply to

Use Markdown with GitHub-flavored code blocks.