Setting up the SQLSRV extension for PHP 7.2 on Ubuntu 18.04.2 LTS

I recently needed to access a SQL Server from PHP for a project I was working on, after some online research, I was able to get the extension up & running on the server.

These are the steps I took to get it setup:

First things first, I started by installing some default packages in addition to Apache2 and the latest PHP version available (in this case, it defaulted to PHP 7.2):

sudo apt-get install vim curl git zip unzip htop apache2 php libapache2-mod-php php-mysql

I then found this online tutorial, How to Install the PHP SQLSRV Extension, that got me started:

curl -s | sudo apt-key add -
sudo bash -c "curl -s > /etc/apt/sources.list.d/mssql-release.list"
sudo apt-get update
sudo ACCEPT_EULA=Y apt-get -y install msodbcsql17 mssql-tools
sudo apt-get -y install unixodbc-dev

however, the pecl7.X-sp command didn’t worked, so after some more online research, found the way to make it work:

sudo apt-get -y install gcc g++ make autoconf libc-dev pkg-config
sudo apt-get install php-pear php-dev
sudo pecl install sqlsrv
sudo pecl install pdo_sqlsrv

at this point, I had the extension built and ready to go, I then proceeded to create the necessary .ini files so that PHP can pick it up:

sudo bash -c "echo > /etc/php/7.2/mods-available/sqlsrv.ini"
sudo ln -s /etc/php/7.2/mods-available/sqlsrv.ini /etc/php/7.2/apache2/conf.d/sqlsrv.ini
sudo ln -s /etc/php/7.2/mods-available/sqlsrv.ini /etc/php/7.2/cli/conf.d/sqlsrv.ini
sudo bash -c "echo > /etc/php/7.2/mods-available/pdo_sqlsrv.ini"
sudo ln -s /etc/php/7.2/mods-available/pdo_sqlsrv.ini /etc/php/7.2/apache2/conf.d/pdo_sqlsrv.ini
sudo ln -s /etc/php/7.2/mods-available/pdo_sqlsrv.ini /etc/php/7.2/cli/conf.d/pdo_sqlsrv.ini

and final step, was to restart Apache2:

sudo systemctl restart apache2

and we are good to go!


Out of the night that covers me, 
      Black as the pit from pole to pole, 
I thank whatever gods may be 
      For my unconquerable soul. 

In the fell clutch of circumstance 
      I have not winced nor cried aloud. 
Under the bludgeonings of chance 
      My head is bloody, but unbowed. 

Beyond this place of wrath and tears 
      Looms but the Horror of the shade, 
And yet the menace of the years 
      Finds and shall find me unafraid. 

It matters not how strait the gate, 
      How charged with punishments the scroll, 
I am the master of my fate, 
      I am the captain of my soul. 

The Man in the Arena

It is not the critic who counts; not the man who points out how the strong man stumbles, or where the doer of deeds could have done them better. The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood; who strives valiantly; who errs, who comes short again and again, because there is no effort without error and shortcoming; but who does actually strive to do the deeds; who knows great enthusiasms, the great devotions; who spends himself in a worthy cause; who at the best knows in the end the triumph of high achievement, and who at the worst, if he fails, at least fails while daring greatly, so that his place shall never be with those cold and timid souls who neither know victory nor defeat.