在Linode上,我使用ApacheandPHP8.1设置了一个MySQL数据库集群和一个Ubuntu服务器。
当我SSH到Ubuntu服务器时,我能够连接到集群:
mysql --host=lin-xxx-mysql-primary-private.servers.linodedb.net --user=xxx --password --ssl-mode=required
但是,当我运行php artisan migrate
时,我会得到以下错误:
Illuminate\Database\QueryException
SQLSTATE[HY000] [3159] Connections using insecure transport are prohibited while --require_secure_transport=ON. (SQL: select * from information_schema.tables where table_schema = xxxrch and table_name = migrations and table_type = 'BASE TABLE')
at vendor/laravel/framework/src/Illuminate/Database/Connection.php:712
708▕ // If an exception occurs when attempting to run a query, we'll format the error
709▕ // message to include the bindings with SQL, which will make this exception a
710▕ // lot more helpful to the developer instead of just the database's errors.
711▕ catch (Exception $e) {
➜ 712▕ throw new QueryException(
713▕ $query, $this->prepareBindings($bindings), $e
714▕ );
715▕ }
716▕ }
+33 vendor frames
34 artisan:37
Illuminate\Foundation\Console\Kernel::handle()
我没有设置任何其他应答引用的证书/pem文件,但它仍然可以从mysqlclient中运行。
我应该在我的.env
中添加什么到config\database.php
来实现这个工作呢?
发布于 2022-08-01 12:54:33
我是怎么解决这个问题的:
dashboard.
resources\certificates
在config/database.php
中,我添加了:
'sslmode' => env('DB_SSLMODE', 'prefer'),
'options' => extension_loaded('pdo_mysql') && env('APP_ENV') !== 'testing' && env('APP_ENV') !== 'local' ? array_filter([
PDO::MYSQL_ATTR_SSL_CA => resource_path('certificates/certificate.crt'),
PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT => true,
]) : [],
需要注意的一点是,这对于phpunit
测试是行不通的。
https://stackoverflow.com/questions/72714453
复制相似问题