After upgrade to php 8.1, sqlsrv pdo drivers not found

After upgrade to php 8.1 (Linux PHP) , Azure webapp does not seems to have driver for MS SQL. It was OK with php 7.4.

Following this guide (https://learn.microsoft.com/en-us/azure/app-service/deploy-local-git?tabs=cli), steps to build and configure Azure App service was: az appservice plan create -g rg-MyResourceG -n MyPlan --is-linux az webapp create -g rg-MyResource --plan MyPlan --name MyApp --% --runtime "PHP|7.4" --deployment-local-git Change to PHP 8.1 following this guide: https://github.com/Azure/app-service-linux-docs/blob/master/Runtime_Support/php_support.md az webapp config appsettings set --name MyApp --resource-group MyResourceG --settings DEPLOYMENT_BRANCH='main' on my local server: php artisan key:generate --show az webapp config appsettings set --name Glados9L --resource-group rg-blueprism-tst --settings APP_KEY="Output from last command" APP_DEBUG="true" git remote add glados9l https://MyUser@MyApp.scm.azurewebsites.net/MyApp.git git push glados9l main ........... remote: Done in 223 sec(s). remote: remote: Removing existing manifest file remote: Creating a manifest file... remote: Manifest file created. remote: Copying .ostype to manifest output directory. remote: remote: Done in 457 sec(s). remote: Running post deployment command(s)... remote: remote: Generating summary of Oryx build remote: Parsing the build logs remote: Found 0 issue(s) remote: remote: Build Summary : remote: =============== remote: Errors (0) remote: Warnings (0) remote: remote: Triggering recycle (preview mode disabled). remote: Deployment successful. deployer = deploymentPath = remote: Deployment Logs : 'https://glados9l.scm.azurewebsites.net/newui/jsonviewer?view_url=/api/deployments/ef2b3e8ce9341d66fa5e64826721e09085dbe214/log' To https://myplan.scm.azurewebsites.net/Glados9L.git

  • [new branch] main -> main
root@9dcf7762daa9:/home# php -i | grep sqlsrv
Cannot load Zend OPcache - it was already loaded
root@9dcf7762daa9:/home# odbcinst -j
unixODBC 2.3.7
DRIVERS............: /etc/odbcinst.ini
SYSTEM DATA SOURCES: /etc/odbc.ini
FILE DATA SOURCES..: /etc/ODBCDataSources
USER DATA SOURCES..: /root/.odbc.ini
SQLULEN Size.......: 8
SQLLEN Size........: 8
SQLSETPOSIROW Size.: 8
root@9dcf7762daa9:/home# php -v
Cannot load Zend OPcache - it was already loaded
PHP 8.1.6 (cli) (built: Aug 17 2022 07:43:32) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.6, Copyright (c) Zend Technologies
    with Zend OPcache v8.1.6, Copyright (c), by Zend Technologies
root@9dcf7762daa9:/home#

Answer

Solution:

It is a known issue that pdo_sqlsrv is missing in PHP 8.1 image and according to this pull request, they are adding this driver soon.

As for now, you can download and enable it manually by following this post

Answer

Solution:

I have the same issue. My app was working perfectly for a few years. After switching the azure webapp from PHP7.4 to PHP8, the connection with the SQL server fail. (PHP7.4 is depreciated soon)

I get this error message on when I connect to the page with my browser.

Error connedmg to SOL Server PDOException Obred ( [message protected] => could not find driver [string Excephorrpnvate]=> [code protected] => 0 [file protected] -> ihome/siteAmwroot/DEV railtypeWrthProcess php [line protected] => 122 [trace Exception pnvate]=> Array ( [0] => Array ( [file] => /home/site/wwwroot/DEVraillypeWith Process php [line] => 122 [function] -> construct [class] => POO [type] => -> [args] => Array ( [0] sglsry server - lcp delachauxrailtechbddserver database windows net,1433, Database = BDDWeldingKrtAPP [1] => weldingKrtApp01 [2] => ****** ) ) ) [previous Exception pnvate]=> [errorInfo] ) 1

Here how I connect to the server with PHP.

try {
    $conn = new PDO("sqlsrv:server = tcp:delachauxrailtechbddserver.database.windows.net,1433; Database = BDDWeldingKitAPP", "weldingKitApp01", "******");
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
    print("Error connecting to SQL Server.");
    die(print_r($e));
}

The webapp was created using the Azure console interface. Not with command.

Thank you for your support.

Source