Mac M1 SQL Server SQLSrv OpenSSL library could not be loaded, make sure OpenSSL 1.0 or 1.1 is installed

Viewed 1955

I just bought a M1 Mac mini running Big Sur 11.6, I've installed PHP 7.3, msodbcsql17, mssql-tools, sqlsrv and pdo_sqlsrv.

But when I try to connect using sqlsrv, the following error happens [Microsoft][ODBC Driver 17 for SQL Server]SSL Provider: [OpenSSL library could not be loaded, make sure OpenSSL 1.0 or 1.1 is installed]

I've installed openssl@1.1 via brew and my profile contains

export PATH="/opt/homebrew/opt/openssl@1.1/bin:$PATH"

It seems like PHP is using the correct version, when printing echo OPENSSL_VERSION_TEXT, it says OpenSSL 1.1.1l 24 Aug 2021

I'm not sure what else to try, to make it work?

2 Answers

For M1 Mac, the default location of brew install is /opt/homebrew, instead of /usr/local. Please refer to this link. Therefore, the symlink you need to add/change is:

ln -sfn /opt/homebrew/Cellar/openssl@1.1/1.1.1m /opt/homebrew/opt/openssl

Using option -f as you're forcing to replace the link, while using -n as the source link is a directory. Of course, change the version if your openssl is not 1.1.1m.

I had the same "OpenSSL library could not be loaded" error today (on an Intel Mac) when trying to connect via isql. (Also, using python, as pyodbc error '08001': ODBC Driver 17 for SQL Server client unable to establish connection).

Apparently, as of early October 2021, the latest SQL Server ODBC Driver is not compatible with the latest version 3 of OpenSSL.

See: https://github.com/microsoft/homebrew-mssql-release/issues/59.

Diagnosis: Check which OpenSSL version is being called via:

ls -l /usr/local/opt/openssl/lib 

You should see an entry for OpenSSL 1.0 or 1.1 (eg libssl.dylib -> libssl.1.1.dylib); when I was having this issue it showed libssl.dylib -> libssl.3.dylib.

The workaround is just to create a symlink. (Use "brew info openssl@1.1" to check the filename/path.) For example:

ln -s /usr/local/Cellar/openssl@1.1/1.1.1l_1 /usr/local/opt/openssl
Related