Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Install Official MSSQL driver for Unbuntu 14.04 - pdo_sqlsrv
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo -i export CPPFLAGS="-DSIZEOF_LONG_INT=8"
sudo apt-get -y install gcc-5 g++-5
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-5 60 --slave /usr/bin/g++ g++ /usr/bin/g++-5
cd ~
echo "Configuring the unixODBC 2.3.1 Driver Manager"
tar -xzf unixODBC-2.3.1.tar.gz
cd unixODBC-2.3.1/
./configure --prefix=/usr --libdir=/usr/lib64 --sysconfdir=/etc --disable-gui --disable-drivers --enable-iconv --with-iconv-char-enc=UTF8 --with-iconv-ucode-enc=UTF16LE 1> odbc_con.log 2> make_err.log
echo "Building and Installing the unixODBC 2.3.1 Driver Manager"
sudo make 1> make_std.log 2> make_err.log
sudo make install 1> makeinstall_std.log 2> makeinstall_err.log
cd ~
echo "Downloading the Microsoft ODBC Driver 13 for SQL Server - Ubuntu"
wget "" -O msodbcsql-
tar -xzf msodbcsql-
cd msodbcsql-
echo "Installing Dependencies"
sudo apt-get -y install libssl1.0.0
sudo apt-get -y install libgss3
sudo echo "/usr/lib64" >> /etc/
sudo ldconfig
echo "Installing the Microsoft ODBC Driver 13 for SQL Server - Ubuntu"
sudo bash ./ install --force --accept-license
cd ~
echo "Compiling PHP driver"
sudo apt-get -y install php7.0-dev
tar -xzf 4.0.6-Linux.tar.gz
cd msphpsql-4.0.6-Linux/source/pdo_sqlsrv/
phpize && ./configure CXXFLAGS=-std=c++11 && make
sudo make install
echo "Enabling Driver for php7.0-fpm and CLI"
sudo bash -c 'echo -e "; configuration for php common module \n; priority=10 \" > /etc/php/7.0/mods-available/pdo_sqlsrv.ini'
sudo ln -s /etc/php/7.0/mods-available/pdo_sqlsrv.ini /etc/php/7.0/fpm/conf.d/20-pdo_sqlsrv.ini
sudo ln -s /etc/php/7.0/mods-available/pdo_sqlsrv.ini /etc/php/7.0/cli/conf.d/20-pdo_sqlsrv.ini
cd ~
echo "Cleaning up.."
sudo rm -rf msphpsql-4.0.6-Linux/
sudo rm -rf unixODBC-2.3.1/
sudo rm -rf msodbcsql-
sudo rm 4.0.6-Linux.tar.gz
sudo rm msodbcsql-
sudo rm unixODBC-2.3.1.tar.gz
echo "All done, please be sure to test via the CLI & restart php7.0-fpm once complete."
php -i | grep 'PDO drivers'
Copy link

How to work this around for php 7.2. Will changing 7.0 to 7.2 work in this case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment