You would need to install both PHP ODBC extension and Microsoft's ODBC drivers for SQL server.
Install PHP ODBC Extension
sudo apt-get install php7.2-odbc
# Note that on Ubuntu 16.04 and earlier you'll need to register this PPA first.
sudo add-apt-repository ppa:ondrej/php
Install the Microsoft ODBC Driver 17 for SQL Server
Import GPG keys:
bash curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
Register the Microsoft Ubuntu repository:
curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list | sudo tee /etc/apt/sources.list.d/msprod.list
# Note replace 16.04 in package URL aboive with your Ubuntu version. i.e. 14.04, 18.04, etc.
Download the drivers for your version of Ubuntu:
bash sudo ACCEPT_EULA=Y apt-get install msodbcsql17
Install optional bcp and sqlcmd tools:
bash sudo ACCEPT_EULA=Y apt-get install mssql-tool
Connect from your PHP application
<?php
$dsn = 'Driver={ODBC Driver 17 for SQL Server};Server=server.domain;Database=database_name';
$username = 'your_username';
$password = 'your_password';
if($connection = odbc_connect($dsn, $username, $password, SQL_CUR_USE_ODBC)) {
echo "Connected to the datasource.";
} else {
echo "Could not connect to the datasource.";
}
Reference: https://learn.microsoft.com/en-us/sql/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server?view=sql-server-2017