Have you already tried to set this in the database.php config ?
Laravel Can't Verify SSL Certificate
Hi, I am new to Laravel and I tried to connect an Azure postgreSQL database using Laravel 11, but it keeps telling me that it can't verify the SSL certificate. When I tried to connect to the database using a test.php file I didn't have any problem connecting to the database.
But when I try to edit the .env file give it the same credentials as the test.php, run it, and it gives the error of "SQLSTATE[08006] [7] SSL error: certificate verify failed" I have asked ChatGPT for help and I've tried to follow it, but it didn't help.
I don't know whether the pathing for the SSL certificate might give the effect or not, since in the .env file, I didn't put the path for the SSL certificate, but chatGPT said it should not be a problem. so I'm stuck right now.
test.php code:
$conn = pg_connect("host=<host address> port=<port number> dbname=<database name> user=<username> password=<password> sslmode=require sslrootcert=c:\ssl\DigiCertGlobalRootCA.crt.pem");
I solved it by using the following config on the .env file and database.php on my Laravel project:
.env file:
DB_CONNECTION=pgsql
DB_HOST=<your_host>
DB_PORT=<your_port>
DB_DATABASE=<your_database_name>
DB_USERNAME=<username>
DB_PASSWORD=<password>
# add your SSL certificate path following the example below
DB_URL=pgsql://<username>:<password>@<your_host>:<your_port>/<your_database_name>?sslmode=require&sslrootcert=<path_to_your_certificate>
database config in 'config/database.php'
'pgsql' => [
'driver' => 'pgsql',
'url' => env('DB_URL'), // add this line
# ..... add the rest of your settings
],
I don't know whether the above solution is the best solution or not, but at least it's working for me.
Please or to participate in this conversation.