PHP 7.0.33 with sqlsrv gives error "SSL Provider: [OpenSSL library could not be loaded, make sure OpenSSL 1.0 or 1.1 is installed]"

Viewed 1388

I'm using sqlsrv module with PHP 7.0.33, Apache 2.2.34 on MacOS Catalina (10.15.7).

The execution of sqlsrv_connect in this code block

$serverName = "192.168.4.14";
$connectionInfo = array(
    "Database" => "mydatabase",
    "UID" => "myusername",
    "PWD" => "mypassword"
);
// Create connection
$conn = sqlsrv_connect($serverName, $connectionInfo);

gives me the error

[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 have more versions of PHP installed on my Mac, so I supposed this was the cause of the error, but opening the info.php page, it tells me that the OpneSSL module is loaded:

enter image description here

Here are the details about pdo_sqlsrv module given by info.php:

enter image description here

And sqlsrv module:

enter image description here

Do you have any suggestion about what else may I check to found the cause of the error?

Thank you all in advance.

EDIT: the info.php shows me that in the configure command was used --with-openssl=/Applications/MAMP/Library which is the v1.0.2o.

2 Answers

Resolved!!!! As reported here: https://github.com/microsoft/homebrew-mssql-release/issues/37.

In /usr/local/opt homebrew has created the symlink openssl@1.1.

The issue was related to the impossibility for the Microsoft driver to read a dir with the format opnessl@1.1.

The solution is so simple as recreating the symlink omitting the @1.1 suffix:

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

Thank you all for your contributions!

What seems to be the problem is that you don't have the correct version of the OpenSSL libs installed on your machine (seems to be a issue on catalina).

Step 1: Check if you have the correct version installed.

Run the following command (assuming the location for macOS): ls -l /usr/local/opt/openssl/lib

if this does not work, run the following command: openssl version

This should show which versions of OpenSSL libraries you have installed. If you have 1.0 or 1.1 you are done

Step 2: Install or upgrade

If you have openssl installed (but not the right version), upgrade it with brew upgrade openssl

If you dont have openssl installed, install it with brew install openssl

Step 3 Test

After these steps this error should be resolved

Related