1

Here's the complete error message:

SQLSTATE[08001]: [Microsoft][ODBC Driver 18 for SQL Server]SSL Provider: The certificate chain was issued by an authority that is not trusted.

I've a private company project, currently the project is developed using CodeIgniter3 and the database uses Microsoft SQL Server. I need to turn the project into Laravel9. So, I follow several instruction until meet some tutorial here:

The installation didn't face much problem. I follow the procedure from the first list with the suitable driver. But then facing the error as mentioned above.

Dale K
  • 25,246
  • 15
  • 42
  • 71
dhanyn10
  • 704
  • 1
  • 9
  • 26
  • 1
    SQL Server instances are, by default, installed with self-signed X.509 certificates. So how have you configured your [Connection Options](https://learn.microsoft.com/en-us/sql/connect/php/connection-options)? You would have three options: 1) get the public key portion of the certificate from the server and add it to your Trusted Certificates store, or 2) use `TrustServerCertificate=1`, or 3) use `Encrypt=0`. `Encrypt=0` is the least desirable option because all of your SQL Server communications will be sent across the network unencrypted, i.e.: "in the clear". – AlwaysLearning Mar 16 '22 at 09:49

1 Answers1

17

i found the solution here: Laravel SQL Server connection with ENCRYPT=yes trustServerCertificate=true

it also working for laravel 9, update the config file config/database.php like below

'sqlsrv' => [
    'driver' => 'sqlsrv',
    'host' => env('DB_HOST', 'localhost'),
    'database' => env('DB_DATABASE', 'forge'),
    'username' => env('DB_USERNAME', 'forge'),
    'password' => env('DB_PASSWORD', ''),
    'charset' => 'utf8',
    'prefix' => '',
    'encrypt' => 'yes',
    'trust_server_certificate' => true,
],
dhanyn10
  • 704
  • 1
  • 9
  • 26