To install the Microsoft ODBC 17 driver for SQL Server on macOS, follow these commands:
Open a terminal on your macOS.
Run the following command to install Homebrew if you havenβt installed it yet:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
brew tap microsoft/mssql-release https://github.com/Microsoft/homebrew-mssql-release
brew update
HOMEBREW_ACCEPT_EULA=Y brew install msodbcsql17 mssql-tools
This will install the ODBC 17 driver and SQL Server tools.
msodbcsql
v17 package, ensure to uninstall it to avoid conflicts. You can uninstall it with the following command:brew uninstall msodbcsql
The msodbcsql17
package can be installed alongside the msodbcsql
v13 package.
php -v
If PHP is not in your path or is not the correct version, run the following commands:
brew link --force --overwrite php@8.2
If you are using a Mac with Apple M1 ARM64, you may need to set the path:
export PATH="/opt/homebrew/bin:$PATH"
brew install autoconf automake libtool
sudo pecl install sqlsrv
sudo pecl install pdo_sqlsrv
If you are using a Mac with Apple M1 ARM64, use these commands instead:
sudo CXXFLAGS="-I/opt/homebrew/opt/unixodbc/include/" LDFLAGS="-L/opt/homebrew/lib/" pecl install sqlsrv
sudo CXXFLAGS="-I/opt/homebrew/opt/unixodbc/include/" LDFLAGS="-L/opt/homebrew/lib/" pecl install pdo_sqlsrv
brew services restart httpd
With these steps, you should have the Microsoft SQL Server ODBC 17 driver and the necessary PHP drivers installed on your macOS system. This will allow you to connect to a SQL Server database from your PHP application.