Achraf Khouadja
Achraf Khouadja

Reputation: 6269

sqlsrv could not find driver laravel on azure

After deploying the app, I changed my env file to match the connection credentials for the sql server which was up and already running.

There is an error when I visit the website

> PDOException in Connector.php line 55: could not find driver in
> Connector.php line 55 at
> PDO->__construct('sqlsrv:Server=xxxx.database.windows.net;Database=xxxx', 'xxxx@xxxx', 'xxxxxx', array('0', '2', '0', false)) in Connector.php
> line 55

I tried opening the console from azure portal and write php artisan migrate, it showed the same error.

enter image description here

Anyone knows how can i manage to make this work?

Upvotes: 3

Views: 4811

Answers (1)

Gary Liu
Gary Liu

Reputation: 13918

Have you enabled the php_sqlsrv and php_pdo_sqlsrv extension on Azure? You can use phpinfo() to check the variables and extensions of your PHP runtime on Azure.

Be default, the DLL libraries php_sqlsrv and php_pdo_sqlsrv have been installed in the PHP ext folder on Azure, but haven't been configured in PHP runtime. So we need to configure the extensions manually:

  1. Create a file named .user.ini at the root directory of your application on Azure.

  2. Write the following content in .user.ini:

    extension=php_pdo_sqlsrv.dll
    extension=php_sqlsrv.dll
    
  3. Restart your application. Check the extension of sqlsrv and pdo_sqlsrv again.

update

As the libraries sqlsrv and pdo sqlsrv for PHP 7 are available now. Please try the following to enable the sqlsrv extension for PHP 7 on Azure Web Apps:

  1. Download the extension package for PHP 7 from https://github.com/Azure/msphpsql/tree/PHP-7.0, unzip for following use.
  2. Follow the guide of https://azure.microsoft.com/en-us/documentation/articles/web-sites-php-configure/#how-to-enable-extensions-in-the-default-php-runtime to upload DLL libraries and configure in PHP runtime.(by default, Azure Web App requires X86 with nts version. Please use the libraries in msphpsql-PHP-7.0\binaries\x86 you unzip before, and use php_sqlsrv_7_nts.dll and php_pdo_sqlsrv_7_nts.dll)
  3. Restart the site after configuring the settings.

Any further concern, please feel free to let me know.

Upvotes: 3

Related Questions