Laravel cannot connect to SQL Server after moving to ODBC Driver 18
ODBC Driver 18 for SQL Server]SSL Provider: [error:1416F086Short 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.
Fix it fast
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:show2Match what you see, then jump to its fix
- 1
The 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
The 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
A 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
- 1
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" .env2Fix
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=true3Verify
Clear the cached configuration and connect again.
php artisan config:clear
php artisan db:showConfirmed by learn.microsoft.com
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" .env2Fix
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.com3Verify
Reconnect and confirm the database overview prints.
php artisan db:showConfirmed by learn.microsoft.com
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" .env2Fix
Set encrypt to no for this connection. Prefer the first two fixes whenever the traffic leaves a trusted network.
# .env
DB_ENCRYPT=no3Verify
Clear the config cache and connect.
php artisan config:clear
php artisan db:showConfirmed by learn.microsoft.com
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 says the gd extension is missing on a Laravel project
composer install or composer update stops on a package that requires ext-gd
Composer refuses to install a package that requires ext-gd when the PHP binary running Composer has no GD extension.
4 causes, each with a fixBack 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 fixBack end
composer install says the lock file is not compatible and asks for update
Your lock file does not contain a compatible set of packages. Please run composer update.
composer install checked the locked packages against this machine's PHP and extensions and found a conflict.
3 causes, each with a fixBack 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 fixBack end
composer require laravel/passport stops with 'requirements could not be resolved'
... but these were not loaded, likely because it conflicts with another require.
Composer found no Passport release that fits your project at once.
4 causes, each with a fixBack end
Composer says the root composer.json requires a PHP version your PHP does not satisfy
Your requirements could not be resolved to an installable set of packages.
Composer compares the php constraint in your composer.json, or in a package, with the PHP that runs Composer.
3 causes, each with a fix