Troubleshooting Could not find driver sqlsrv on Windows PHP 8.0.1
If you are deploying a Laravel application or any PHP project on Windows IIS and encounter the error Could not find driver {sqlsrv}, the issue almost always stems from a mismatch between the extension name, the architecture of your PHP binary, and the specific DLL files you have downloaded. The error log provides a clear clue: Unable to load dynamic library 'php_sqlsrv_72_ts.dll' or 'pdo_sqlsrv', followed by (ImpossÃvel localizar o módulo especificado). This Portuguese string translates to "unable to locate the specified module," but the real culprit is often that PHP cannot even find the file path you specified, or it finds a file with an incompatible architecture.
The most common mistake involves downloading the wrong driver package for your specific PHP version and threading model. The source material highlights attempts with PHP 8.0.1 (implied by the title, though logs show Jan 2021). Even if you think you are on PHP 8.0, ensure you are actually running that version. The sqlsrv driver architecture has changed significantly between PHP versions. If you download a DLL compiled for PHP 7.4 and try to load it into PHP 8.0, the loader will fail immediately because the internal API structures have diverged.
When configuring IIS, you must be precise about which extension to enable in php.ini. For SQL Server connectivity, there are two distinct drivers: sqlsrv (the legacy driver) and pdo_sqlsrv (the recommended modern driver). The error logs show attempts to load both resulting in "file not found" errors. This specific error message on Windows usually indicates one of two things:
- Architecture Mismatch: You downloaded a 64-bit DLL for a 32-bit PHP installation, or vice versa. IIS on modern Windows Server is almost exclusively 64-bit. If your PHP binary is 32-bit, it cannot load 64-bit drivers. Check your
php -i | findstr "Architecture"command output first. - Missing Dependencies: The SQL Server driver relies on the Microsoft ODBC Driver for SQL Server being installed and configured correctly in the Windows Registry. Unlike
pdo_odbc, which might work with a generic setup,sqlsrvrequires specific system components that are not included in the standard PHP distribution.
Regarding the filename confusion seen in the logs (php_sqlsrv_72_ts.dll vs php_pdo_sqlsrv), note that the _ts suffix stands for Thread Safe. If your PHP build is non-thread safe (NTS), you must download the _nts version of the driver. The error log explicitly shows PHP trying to load C:\php\ext\php_sqlsrv_72_ts.dll. If your php.ini points to this file but the actual binary on disk is named differently, or if the architecture doesn't match, PHP will throw the "unable to locate" warning even if the file exists.
In scenarios where the legacy sqlsrv extension fails, switching to the PDO interface is the standard recommendation. However, simply adding extension=pdo_sqlsrv to php.ini is insufficient if the underlying DLL does not exist in the ext folder or matches your architecture. The error log shows PHP looking for C:\php\ext\pdo_sqlsrv. If you downloaded a PECL package from pecl.php.net, ensure the release corresponds exactly to your PHP version and build type (TS vs NTS).
If you are using Laravel, remember that Composer does not install these drivers. You must manually download the appropriate DLL for your specific PHP installation architecture and place it in the ext directory. Once placed, restart the IIS application pool or the server. If the error persists after confirming architecture compatibility (e.g., both 64-bit), verify that the Microsoft ODBC Driver for SQL Server is installed on the server machine. Without this system-level dependency, the driver DLL will fail to load regardless of how correctly it is configured in PHP.
For production environments where maintaining legacy drivers is problematic, consider switching to PDO MySQL or PostgreSQL if feasible, as they are often easier to manage across different operating systems. However, for SQL Server specific needs, ensure you have selected the correct php_sqlsrv_*.dll or php_pdo_sqlsrv.dll from the official Microsoft download page that matches your PHP version and threading model exactly.