framework: Undefined class constant 'MYSQL_ATTR_SSL_CA' during `laravel new`

  • Laravel Version: 5.8
  • PHP Version: 7.2
  • Database Driver & Version: (Without pdo_mysql)

Description:

When I run laravel new foo using php without pdo_mysql extension, the following error message was output.

% laravel new foo
Crafting application...
(snip)
Generating optimized autoload files
> @php -r "file_exists('.env') || copy('.env.example', '.env');"
> @php artisan key:generate --ansi

In database.php line 58:

  Undefined class constant 'MYSQL_ATTR_SSL_CA'


Script @php artisan key:generate --ansi handling the post-create-project-cmd event returned with error code 1
Application ready! Build something amazing.

And the value of APP_KEY in the .env file remained empty.

Steps To Reproduce:

Run laravel new foo using php without pdo_mysql extension.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 16 (13 by maintainers)

Most upvoted comments

No stack trace was displayed.

I greped under the foo directory and found that it is only config/database.php that uses MYSQL_ATTR_SSL_CA.

        'mysql' => [
            'driver' => 'mysql',
            '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,
            'options' => array_filter([
                PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
            ]),
        ],

Before using PDO::MYSQL_ATTR_SSL_CA, I think that it is necessary to check whether pdo_mysql extension is loaded.

For example:

            'options' => !extension_loaded('pdo_mysql') ? [] : array_filter([
                PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
            ]),

I solved it installing php*-mysql: sudo apt-get install php7.2-mysql

We’ve commented that section out for now so it’s opt-in instead. You can do the same in your config: https://github.com/laravel/laravel/commit/a0f6bcc773f3895db0ca4a85101b9a3ef2f95782