I'm new to Linux. I have provisioned a new Ubuntu 16.04 server, added LAMP via Tasksel, and added PhpMyAdmin. I added my web app to the html folder, and ran my MySQL scripts. This part works fine. I have a PHP page that queries a remote SQL Server. This is where my issue is:

I installed the SQL Server ODBC Driver per instructions:


udo su 
sh -c 'echo "deb [arch=amd64]
https://apt-mo.trafficmanager.net/repos/mssql-ubuntu-xenial-release/xenial main" > /etc/apt/sources.list.d/mssqlpreview.list' 
sudo apt-key adv --keyserver apt-mo.trafficmanager.net --recv-keys 417A0893
apt-get update 
apt-get install msodbcsql unixodbc-dev-utf16

SQL Server ODBC is not listed in PhpInfo().

When I hit the page with the remote SQL Server query, I find an error in my Apache2 error log:

[Tue Nov 01 04:42:52.651772 2016] [:error] [pid 1306] [client ::1:33146]
PHP Fatal error: Uncaught Error: Call to undefined function odbc_connect() in /var/www/html/xxxxxxx.php:67\n
Stack trace:\n#0 {main}\n thrown in /var/www/html/xxxxxxx.php on line 67

What am I missing?


I had the same issue with the repo linked in MSDN.

You would need to install the php-odbc package which needs a library that conflicts with the one from the microsoft repo.

I installed the driver manually with the following commands:

sudo apt-get -y install build-essential
cd /tmp/
wget ftp://ftp.unixodbc.org/pub/unixODBC/unixODBC-2.3.4.tar.gz
tar xvf unixODBC-2.3.4.tar.gz
cd unixODBC-2.3.4/
./configure --enable-gui=no --enable-drivers=no --enable-iconv --with-iconv-char-enc=UTF8 --with-iconv-ucode-enc=UTF16LE --libdir=/usr/lib/x86_64-linux-gnu --prefix=/usr --sysconfdir=/etc
sudo make install

sudo apt-get install openssl libkrb5-3 libc6 e2fsprogs

cd /tmp/
wget http://download.microsoft.com/download/B/C/D/BCDD264C-7517-4B7D-8159-C99FC5535680/RedHat6/msodbcsql-11.0.2270.0.tar.gz
tar xvf msodbcsql-11.0.2270.0.tar.gz
cd msodbcsql-11.0.2270.0/
sudo bash install.sh install --force --accept-license

sudo ln -s /lib/x86_64-linux-gnu/libcrypto.so.1.0.0 /usr/lib/x86_64-linux-gnu/libcrypto.so.10
sudo ln -s /lib/x86_64-linux-gnu/libssl.so.1.0.0 /usr/lib/x86_64-linux-gnu/libssl.so.10
sudo ln -s /usr/lib/x86_64-linux-gnu/libodbcinst.so.2.0.0 /usr/lib/x86_64-linux-gnu/libodbcinst.so.1

You can enter your connections now in /etc/odbc.ini and replace IP and password. e.g.:

Driver = ODBC Driver 11 for SQL Server
Server =,1433
Database = TEST

and access with PDO:

$db = new PDO('odbc:test', 'USERNAME' 'PASSWORD');
  • The comma-separated port isn't very obvious, but it worked for me. Thanks! – Ruben S Oct 29 '18 at 15:12

As per Installing the Microsoft ODBC Driver for SQL Server on Linux and macOS page, the suggested installation steps on Ubuntu are:

sudo su 
curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list > /etc/apt/sources.list.d/mssql-release.list
sudo apt-get update
sudo ACCEPT_EULA=Y apt-get install msodbcsql
# optional: for bcp and sqlcmd
sudo ACCEPT_EULA=Y apt-get install mssql-tools
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
source ~/.bashrc
# optional: for unixODBC development headers
sudo apt-get install unixodbc-dev

Then make sure to enable odbc extension for your Apache, e.g. a2enmod odbc, then check by: apache2ctl -M. If you don't have this extension, install via apt-get install php-odbc (use yum in case of CentOS).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.