Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jorgeborges/0a771505c5092ac8d09d92069b7abc0b to your computer and use it in GitHub Desktop.
Save jorgeborges/0a771505c5092ac8d09d92069b7abc0b to your computer and use it in GitHub Desktop.
Install PHP MSSQL Driver in MacOS (Mojave)

Installing Brew

$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Installing MSSQL Tools

brew tap microsoft/mssql-release https://github.com/Microsoft/homebrew-mssql-release
brew update
brew install msodbcsql17 mssql-tools

If you installed this formula with the registration option (default), you'll need to manually remove [ODBC Driver 17 for SQL Server] section from odbcinst.ini after the formula is uninstalled. This can be done by executing the following command:

$ odbcinst -u -d -n "ODBC Driver 17 for SQL Server"

Install dependencies:

$ brew install autoconf automake libtool

Install PHP Drivers for MSSQL

$ sudo pecl install sqlsrv
$ sudo pecl install pdo_sqlsrv

In case your MSSQL .so files didn't load properly, you can find the exact location of the files with following command:

$ find . -name pdo_sqlsrv.so -print
$ find . -name sqlsrv.so -print

In my case I got the following path for the files. Now

/usr/local/lib/php/pecl/20170718/sqlsrv.so
/usr/local/lib/php/pecl/20170718/pdo_sqlsrv.so

Next, just copy the files to your respective PHP Version lib directory:

cp /usr/local/lib/php/pecl/20170718/sqlsrv.so /usr/local/Cellar/php@7.2/7.2.13/lib/php/20170718/
cp /usr/local/lib/php/pecl/20170718/pdo_sqlsrv.so /usr/local/Cellar/php@7.2/7.2.13/lib/php/20170718/

Then make sure the following extensions is loaded in php.ini

extension="pdo_sqlsrv.so"
extension="sqlsrv.so"

Use php -m | grep sqlsrv to check the extensions is loaded properly.

php -m | grep sqlsrv
pdo_sqlsrv
sqlsrv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment