Updated June 2026. Tested on Laravel 13 and PHP 8.4.
Connecting Laravel to Microsoft SQL Server is straightforward once the right PHP pieces are in place. The catch with SQL Server, unlike MySQL, is that the driver is not bundled, so most of the work is installing it.
Install the driver pieces
SQL Server needs two things on top of PHP: Microsoft's ODBC driver, and the pdo_sqlsrv PHP extension that talks to it. On Ubuntu you install the Microsoft ODBC driver from Microsoft's repository, then add the PHP extension.
sudo pecl install sqlsrv pdo_sqlsrv
Enable them for PHP, then confirm they loaded.
php -m | grep sqlsrv
If pdo_sqlsrv is not in the list, Laravel will throw "could not find driver" no matter how correct your settings are. This is the step people miss.
Set the .env
DB_CONNECTION=sqlsrv
DB_HOST=127.0.0.1
DB_PORT=1433
DB_DATABASE=techalyst
DB_USERNAME=sa
DB_PASSWORD=YourStrong!Passw0rd
SQL Server listens on port 1433 by default.
The connection in config/database.php
Laravel ships with an sqlsrv connection already defined.
'sqlsrv' => [
'driver' => 'sqlsrv',
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '1433'),
'database' => env('DB_DATABASE', 'laravel'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'prefix' => '',
],
Test it
php artisan migrate
If the driver extensions are loaded and the credentials are right, the migration runs against SQL Server. If you hit a certificate or encryption error on a local or dev server, you can add 'encrypt' => 'no' to the connection array while you sort out TLS, though on production you want encryption on. Questions welcome in the comments.
All comments ()
No comments yet
Be the first to leave a comment on this post.