Microsoft Azure Doesn’t Load The SQL Server PDO Driver In PHP Version 5.5

Another of those “learn from my mistakes” moments: Azure Web Sites don’t include the SQL Server PDO extension if your site is running PHP 5.5.

This I learned the hard way today.

I set up my site to run PHP 5.5.11, the version that as of this writing Azure uses. But my script halted without warning; knowing from experience that this meant there was a PHP error, I quickly popped into my site’s log and saw this entry:

[23-Jun-2014 12:52:36 America/Los_Angeles] PHP Warning:  PHP Startup: Unable to load dynamic library 'D:\Program Files (x86)\PHP\v5.5\ext\php_sqlsrv.dll' - The specified module could not be found.

This clearly indicated that the PDO driver for SQL Server wasn’t present. And sure enough, a call to phpinfo() verified as much:

There's no PDO driver for sqlsrv when using PHP version 5.5 on Azure.
There’s no PDO driver for sqlsrv when using PHP version 5.5 on Azure.

By switching back to version 5.4 — which is what Azure will load by default, if you don’t select a different one — the sqlsrv PDO driver was loaded:

The PDO sqlsrv driver is loaded when you use PHP version 5.4 on Azure websites.
The PDO sqlsrv driver is loaded when you use PHP version 5.4 on Azure websites.

Again, it’s worth noting that Azure will use PHP version 5.4.23 if you don’t specify which version of PHP you want to use. And you can set PHP versions — as well as versions of other scripting languages — in the Configure panel of your website’s dashboard:

This is where you set the PHP version for your Azure website. Note that version 5.4 is the default version selected when you create an Azure website.
This is where you set the PHP version for your Azure website. Note that version 5.4 is the default version selected when you create an Azure website.

It’s also worth noting that you can load custom DLLs in Azure hosting, or use a custom PHP runtime, so I could have added the sqlsrv DLL, or built a version of PHP 5.5 with the SQL Server PDO driver, if I really needed version 5.5.

Finally, if you want error reporting in PHP, that can be configured via a .user.ini directive.

All links in this post on delicious: https://delicious.com/dougvdotcom/protip-microsoft-azure-doesnt-sql-server-pdo-support-php-version-5-5

2 Comments

  1. Thanks for this, saved me a certain amount of head scratching! I wonder what the motivation for not running the PDO driver on 5.5 is – there is definitely a driver available for 5.5…

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

  • Check out the Commenting Guidelines before commenting, please!
  • Want to share code? Please put it into a GitHub Gist, CodePen or pastebin and link to that in your comment.
  • Just have a line or two of markup? Wrap them in an appropriate SyntaxHighlighter Evolved shortcode for your programming language, please!