SQL Server Drivers on macOS ​
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)"
- Add the Microsoft SQL Server repository to Homebrew:
brew tap microsoft/mssql-release https://github.com/Microsoft/homebrew-mssql-release
- Update Homebrew:
brew update
- Make sure to accept the Microsoft License Agreement before installing the packages:
HOMEBREW_ACCEPT_EULA=Y brew install msodbcsql17 mssql-tools
This will install the ODBC 17 driver and SQL Server tools.
- If you had previously installed the
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.
- Verify that PHP is in your path. Run the following command to check that you are using the correct PHP version:
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"
- Additionally, you may need to install the GNU Make tools:
brew install autoconf automake libtool
- Install the PHP drivers for Microsoft SQL Server:
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
- Finally, restart Apache if you are using it:
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.