Skip to content

Instantly share code, notes, and snippets.

@nasrulhazim
Last active August 13, 2024 15:04
Show Gist options
  • Save nasrulhazim/404f8e443a447f84186bd382a9bb47f4 to your computer and use it in GitHub Desktop.
Save nasrulhazim/404f8e443a447f84186bd382a9bb47f4 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/[email protected]/7.2.13/lib/php/20170718/
cp /usr/local/lib/php/pecl/20170718/pdo_sqlsrv.so /usr/local/Cellar/[email protected]/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
@AdetolaAremu
Copy link

I am also battling with the same issue

get a Make fail error on both the Pecl install commands. Any thoughts?

     ^~~~~~~

1 error generated. make: *** [pdo_dbh.lo] Error 1 ERROR: `make' failed

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