Install PHP drivers for Microsoft SQL Server on Ubuntu PHP 7.2

On Ubuntu 18.04 server running PHP 7.2, i want to install Microsoft SQL Server module for PHP. You can find PHP module for SQL server at

https://github.com/microsoft/msphpsql

At the time of writing this PHP module only support PHP 7.4 and newer. SO i need to find older version that supported PHP 7.2. On checking release page, i found version 5.8.0 supported PHP 7.2

First install php7.2 dev package with

Instal php modules with pcel

During install, i got error

This is fixed with command

install pdo_sqlsrv with

Run

Enabe PHP modules with

Restart Apache, now phpinfo() shows pdo_sqlsrv

But when accessing PHP script that connect to MS SQL server, i get error

This extension requires the Microsoft ODBC Driver for SQL Server to communicate with SQL Server. Access the following URL to download the ODBC Driver for SQL Server for x64

To fix this, do

For Ubuntu 16.04

For Ubuntu 18.04

For Ubuntu 20.04

Ubuntu 20.10

Update apt cahe

Install Microsoft ODBC

Optional: for bcp and sqlcmd

Now php MS SQL module will work. You can find sample PHP code at

https://gist.github.com/serverok/456b3d1d7295463df42c9822e8db3e5b
https://github.com/microsoft/msphpsql/blob/master/sample/pdo_sqlsrv_sample.php

Here are microsoft documentation

https://docs.microsoft.com/en-us/sql/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server?view=sql-server-2017

https://docs.microsoft.com/en-us/sql/connect/php/installation-tutorial-linux-mac?view=sql-server-ver15

See PHP

Leave a Reply

Your email address will not be published. Required fields are marked *