Search code examples
phplaraveldebianodbcsqlsrv

could not find driver Debian SQL Server PHP


I have a Laravel installation running on a Debian 9.9 server and PHP 7.4.

I need to connect to a SQL Server database on a remote Windows server.

I followed this guide to install the PHP extensions: https://learn.microsoft.com/en-us/sql/connect/php/installation-tutorial-linux-mac?view=sql-server-ver15#installing-the-drivers-on-debian-8-9-and-10

And this one to install the ODBC drivers: https://learn.microsoft.com/en-us/sql/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server?view=sql-server-ver15

I also tried reinstalling PHP.

But even after doing all this, I still can't connect to the database and get this error:

could not find driver (SQL: select * from [table] where [column] = 123)

Thanks

EDIT

This is are the lines where PDO is mentioned in the result of phpinfo()

PDO support => enabled
PDO drivers => mysql, sqlsrv

pdo_sqlsrv

pdo_sqlsrv support => enabled
ExtensionVer => 5.8.0

Directive => Local Value => Master Value
sqlsrv.ClientBufferMaxKBSize => 10240 => 10240
sqlsrv.LogSeverity => 0 => 0
sqlsrv.LogSubsystems => 0 => 0
sqlsrv.SetLocaleInfo => 2 => 2
sqlsrv.WarningsReturnAsErrors => On => On

php --ini shows that these two extensions are enabled:
/etc/php/7.4/cli/conf.d/pdo_sqlsrv.ini,
/etc/php/7.4/cli/conf.d/sqlsrv.ini

PDO::getAvailableDrivers() returns the following:

Array
(
    [0] => mysql
    [1] => sqlsrv
)

Solution

  • Turns out the problem was the Apache configuration. Even after reinstalling it, for some reason I had still an old configuration loaded. I had installed the driver on 7.4 and apache was still serving 7.3.

    I solved it by doing:

    sudo a2dismod php7.3
    sudo a2enmod php7.4
    sudo service apache2 restart