Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

Laravel cannot connect to SQL Server after moving to ODBC Driver 18

ErrorODBC Driver 18 for SQL Server]SSL Provider: [error:1416F086

Short answer

ODBC Driver 18 encrypts every connection by default and checks the server certificate. If SQL Server presents a self-signed certificate, or one issued for a different host name, the TLS handshake fails with the SSL Provider error. Install a trusted certificate, connect by the name in the certificate, or trust the certificate on a private network.

  • Applies to ODBC Driver 18 for SQL Server, PHP 8.3, Laravel 12, pdo_sqlsrv
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Print the full connection error Laravel receives. The words after the error code (self-signed, unable to get local issuer, host name) point to one cause below.

    php artisan db:show
  2. 2Match what you see, then jump to its fix

    1. 1The SSL Provider error appears right after upgrading from Driver 17, or on a fresh server that still uses the certificate SQL Server generated itself.The server certificate is self-signed or not trusted by this machineFix
    2. 2The certificate is trusted, but DB_HOST is an IP address or a short name the certificate was not issued for.You connect by an address that is not in the certificateFix
    3. 3A legacy server on a closed network where Driver 17 worked without encryption.Encryption is not needed on this link and you want the old behaviourFix

What does the error look like?

  • ODBC Driver 18 for SQL Server]SSL Provider: [error:1416F086

Cause 1 of 3

The server certificate is self-signed or not trusted by this machine

1Check

Driver 17 and older defaulted to Encrypt=no. Driver 18 defaults to yes. With Encrypt=yes and TrustServerCertificate=no, the driver checks the server certificate, so an untrusted one fails.

grep -n "encrypt\|trust_server_certificate" config/database.php
grep -n "DB_ENCRYPT\|DB_TRUST_SERVER_CERTIFICATE" .env

2Fix

The proper fix is a certificate from an authority the machine trusts. On a private network or in development you can tell the driver to accept the certificate. The Laravel skeleton lists both keys, commented out, in the sqlsrv connection: remove the comment marks and set the environment variable.

// config/database.php, inside the 'sqlsrv' connection
'encrypt' => env('DB_ENCRYPT', 'yes'),
'trust_server_certificate' => env('DB_TRUST_SERVER_CERTIFICATE', 'false'),

# .env (development or private network only)
DB_TRUST_SERVER_CERTIFICATE=true

3Verify

Clear the cached configuration and connect again.

php artisan config:clear
php artisan db:show

Confirmed by learn.microsoft.com

Did this fix it?

Cause 2 of 3

You connect by an address that is not in the certificate

1Check

The driver compares the host name you connect to with the name in the certificate. If they differ, validation fails even for a trusted certificate.

grep -n "DB_HOST" .env

2Fix

Set DB_HOST to the exact name in the certificate. If you build the ODBC connection string yourself, the HostnameInCertificate keyword (Driver 18 and later) names the host to expect when it differs from Server.

# .env
DB_HOST=sql01.example.com

# ODBC connection string, only if the name cannot be changed
Server=10.0.0.5;HostnameInCertificate=sql01.example.com

3Verify

Reconnect and confirm the database overview prints.

php artisan db:show

Confirmed by learn.microsoft.com

Did this fix it?

Cause 3 of 3

Encryption is not needed on this link and you want the old behaviour

1Check

In the Driver 18 settings table, Encrypt=No together with no forced encryption on the server means the certificate is not checked and data is not encrypted. Choose this only when the network itself is trusted.

grep -n "DB_ENCRYPT" .env

2Fix

Set encrypt to no for this connection. Prefer the first two fixes whenever the traffic leaves a trusted network.

# .env
DB_ENCRYPT=no

3Verify

Clear the config cache and connect.

php artisan config:clear
php artisan db:show

Confirmed by learn.microsoft.com

Did this fix it?

How do I stop it coming back?

  • Install a certificate from a trusted authority on SQL Server and connect by the name it was issued for.
  • Keep encryption on in production; use trust_server_certificate only on development machines.
  • Read the driver's default changes before moving a server from Driver 17 to 18.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Back end

composer require maatwebsite/excel fails to install

Composer says the package needs an older PHP than the one installed

Composer refuses maatwebsite/excel when the PHP version or a PHP extension does not match what the package and PhpSpreadsheet need.

3 causes, each with a fix

Back end

composer require laravel/horizon fails: ext-pcntl is missing

laravel/horizon v1.1.0 requires ext-pcntl * -> the requested PHP extension pcntl is missing from your system

Horizon needs the pcntl extension, and Composer refuses to install it where PHP lacks that extension.

3 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.