Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

AlexElementarteilchen's avatar

HERD and MS SQL drivers on macOS

In case anyone needs this:

Installing MS SQL drivers on macOS when working with HERD

Follow these steps to get the drivers downloaded and installed:

https://learn.microsoft.com/en-us/sql/connect/php/installation-tutorial-linux-mac?view=sql-server-ver16#installing-on-macos

Then click on the HERD menu and chose "Open configuration files" This should open a Finder window showing you the directories for your installed PHP versions.

Open the php.ini files and add these lines:

extension=/opt/homebrew/Cellar/php/8.3.6/pecl/20230831/sqlsrv.so extension=/opt/homebrew/Cellar/php/8.3.6/pecl/20230831/pdo_sqlsrv.so

PHP version and the date might be different for you. You can find out the correct path via your terminal (just 'ls /opt/homebrew/Cellar/php/')

Note: You have to do this again when there is a new php version installed!

Hope this helps

0 likes
10 replies
LaryAI's avatar
Level 58

It seems like the original question is providing a guide on how to install Microsoft SQL Server drivers on macOS for PHP environments managed by HERD (which I assume is a typo and should be "MAMP" or another local server environment). Here's a more detailed solution based on the provided steps:

  1. Install Homebrew if you haven't already, as it's the package manager that will be used to install the necessary components. You can install Homebrew by running the following command in the terminal:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
  1. Install the ODBC driver for SQL Server using Homebrew:
brew tap microsoft/mssql-release https://github.com/Microsoft/homebrew-mssql-release
brew update
brew install msodbcsql17 mssql-tools
  1. Install the PHP drivers for SQL Server. First, make sure you have pecl installed. If not, you can install it with the following command (assuming you're using PHP 8.3 as in the example):
brew install [email protected]

Then, install the sqlsrv and pdo_sqlsrv extensions using pecl:

pecl install sqlsrv
pecl install pdo_sqlsrv
  1. After the installation is complete, you need to enable the extensions in your php.ini file. You can find the correct php.ini file by running:
php --ini

Look for the "Loaded Configuration File" in the output.

  1. Open the php.ini file with a text editor and add the following lines to enable the extensions:
extension=sqlsrv.so
extension=pdo_sqlsrv.so

The paths provided in the original question seem to be specific to a Homebrew installation and may vary depending on the PHP version and the date of the installation. You can find the correct path for the extensions by listing the contents of the PHP Cellar directory:

ls /opt/homebrew/Cellar/php/

Navigate to the appropriate version and directory to find the sqlsrv.so and pdo_sqlsrv.so files.

  1. After adding the extensions to your php.ini file, restart your web server to apply the changes.

  2. Finally, verify that the extensions are loaded by running:

php -m | grep sqlsrv

You should see sqlsrv and pdo_sqlsrv in the output if the extensions were successfully loaded.

Remember to repeat these steps if you update your PHP version, as the extension paths may change.

replicant's avatar

@alexelementarteilchen Great guide!

I used this for php 8.3.15. When I updated php to 8.3.17 I did this all again but I'm getting the following error

SQLSTATE: IMSSP Code: -49 Message: This extension requires the Microsoft ODBC Driver for SQL Server. Access the following URL to download the ODBC Driver for SQL Server for arm64: https://go.microsoft.com/fwlink/?LinkId=163712

Did you have any similar issues with upgrades?

AlexElementarteilchen's avatar

@replicant sorry - I haven't touched that project in a while :-|

The error message indicates that it can't find the ODBC drivers. Maybe re-installing them form the link helps?

arianmasselink's avatar

Over here same problem. I'm on Macbook Pro M1, Using Herd. On PHP 8.4.4 and PHP 8.3.17 same. Not found an solution yet.

jdc1898's avatar

Double check your ODBC driver version. There is 17 and 18 and I have found that in many cases, using the v18 ODBC driver connecting to older versions of MS SQL will fail. I have to drop to v17 for those projects.

colincameron's avatar

I'm having the same issue here. I've tried installing v17 instead and still get the message about downloading ODBC driver.

rockBalancer's avatar

Was working prior. Not working for me anymore. Not sure which update and/or change happened.

I'm running php 8.3.17, Herd 1.17.0, I tried uninstalling ODBC Driver 18, and tried downgrading to 17.

It seems that Herd is now enabling pdo_sqsrv, and sqlsrv extensions by default. All this means - is that you no longer need to include them manually in the php.ini file from Herd's configuration folder - for me, it was kicking a duplicate load warning. But my application phpinfo still loads them after removed them from the manual config file.

I tried uninstalling/reinstalling pdo_sqlsrv and sqlsrv. tried updating and installing msodbcsql via brew. Can't seem to get this to connect anymore.

rockBalancer's avatar

Found the fix:

SQLsrv is not looking in the homebrew ODB installation folder by default, which is why it's not finding your ODBC drivers.

sudo ln -s /opt/homebrew/etc/odbcinst.ini /etc/odbcinst.ini

sudo ln -s /opt/homebrew/etc/odbc.ini /etc/odbc.ini

Symlinking these two ini files to their default location fixes it.

The fix was found here: github.com/beyondcode/herd-community/issues/1279

3 likes
replicant's avatar

@rockBalancer That worked for me!!! Thank you for coming back and posting what worked for you. You saved me a lot of time. Appreciate it.

Please or to participate in this conversation.