Msphpsql: MacOS Big Sur

Created on 11 Nov 2020  路  20Comments  路  Source: microsoft/msphpsql

With MacOS Big Sur set to be released tomorrow, I setup a fresh installation (11.0.1) of the public beta in a VM to test my application + dependencies.

I installed PHP via Homebrew (brew install php) and have 7.4.12 installed.

I then installed the ODBC driver via:

brew tap microsoft/mssql-release https://github.com/Microsoft/homebrew-mssql-release
brew update
HOMEBREW_NO_ENV_FILTERING=1 ACCEPT_EULA=Y brew install msodbcsql17 mssql-tools

The ODBC driver appears to have installed successfully.

Finally, I attempted to install the PDO_SQSRV driver via pecl:

pecl install pdo_sqlsrv

This is resulting in the following messages:

ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [pdo_sqlsrv.la] Error 1
ERROR: `make' failed

I have used the steps above to successfully install PDO_SQLSRV on macOS Catalina, using PHP 7.4.8, which was the latest release at the time.

Thanks

configuration macOS

Most helpful comment

For those who are looking to get the MSSQL driver working on Big Sur, you can manually download the binaries and install them. Here is how I did that:

  1. Download the binaries: https://github.com/Microsoft/msphpsql/releases. I'm running PHP 7.4, so I downloaded the file Mac-7.4.tar under v5.8.1.
  2. Locate the directory your PHP extensions are stored in:
$ php --info | grep extension_dir
extension_dir => /usr/local/lib/php/pecl/20190902 => /usr/local/lib/php/pecl/20190902
sqlite3.extension_dir => no value => no value

In my case, for some reason the extension_dir that PHP reports isn't where other extensions are located: /usr/local/lib/php/20190902 -- note the missing pecl folder. You can put them anywhere you want. If you choose not to use the reported extension_dir you'll simply need to specify the full path to the drivers.

  1. Extract the tar file you downloaded in step 1 and copy the .so files to the extension directory you determined in step 2. There are both threadsafe and non-threadsafe drivers. For a discussion about those, go here. You probably don't need both, but do whatever you like.
  2. Identify where PHP reads its configuration from:
$ php --ini
Configuration File (php.ini) Path: /usr/local/etc/php/7.4
Loaded Configuration File:         /usr/local/etc/php/7.4/php.ini
Scan for additional .ini files in: /usr/local/etc/php/7.4/conf.d  <=== We want this one
Additional .ini files parsed:      /usr/local/etc/php/7.4/conf.d/ext-opcache.ini
  1. Create a file named ext-sqlsrv.conf and place it in the directory listed above. Use PHP's rules (documented in the base php.ini file) for details on how to set yours. Here are a couple of examples:
# Example: Using a full path
$ echo -e "extension=/usr/local/lib/php/20190902/php_sqlsrv_74_nts.so\nextension=/usr/local/lib/php/20190902/php_pdo_sqlsrv_74_nts.so" >/usr/local/etc/php/7.4/conf.d/ext-sqlsrv.ini

# ----- OR -----

# Example: File is located in `extension_dir` and matches PHP's expected naming convention
$ mv /usr/local/lib/php/20190902/php_sqlsrv_74_nts.so /usr/local/lib/php/20190902/php_sqlsrv.so
$ mv /usr/local/lib/php/20190902/php_pdo_sqlsrv_74_nts.so /usr/local/lib/php/20190902/php_pdo_sqlsrv.so
$ echo -e "extension=sqlsrv\nextension=pdo_sqlsrv" >/usr/local/etc/php/7.4/conf.d/ext-sqlsrv.ini
  1. Check to verify that the sqlsrv and pdo_sqlsrv drivers are loaded:
$ php --info | grep 'sqlsrv support'
pdo_sqlsrv support => enabled
sqlsrv support => enabled

All 20 comments

Thanks @keithbrinks we will do the investigation on our side and get back to you on this.

Same error I am getting.

ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [sqlsrv.la] Error 1
ERROR: `make' failed

MAC OS:
image

Brew:
Homebrew 2.5.11 Homebrew/homebrew-core (git revision f4b6f; last commit 2020-11-16)

Pecl:
PEAR Version: 1.10.12 PHP Version: 7.4.12 Zend Engine Version: 3.4.0

Yes @abdulwahhabkhan we are aware of this issue. We do not officially support macOS Big Sur yet, but we are looking into this. Please stay tuned.

Thanks @yitam

I did end up upgrading over the weekend. The driver does work if it was already compiled/installed. Just can't install fresh.

Thanks for the info @keithbrinks. I'm sure some people will find it useful.

Homebrew does not provide support for macOS Big Sur yet but is working on it

Hi @yitam ,

Thanks for the update, do we have any other way to install the SQLSRV meanwhile its get fixed?

I just moved from windows to MAC and due to this struggling a lot :(

Thanks

@abdulwahhabkhan please use other macOS that we officially support, from High Sierra to Catalina.

For those who are looking to get the MSSQL driver working on Big Sur, you can manually download the binaries and install them. Here is how I did that:

  1. Download the binaries: https://github.com/Microsoft/msphpsql/releases. I'm running PHP 7.4, so I downloaded the file Mac-7.4.tar under v5.8.1.
  2. Locate the directory your PHP extensions are stored in:
$ php --info | grep extension_dir
extension_dir => /usr/local/lib/php/pecl/20190902 => /usr/local/lib/php/pecl/20190902
sqlite3.extension_dir => no value => no value

In my case, for some reason the extension_dir that PHP reports isn't where other extensions are located: /usr/local/lib/php/20190902 -- note the missing pecl folder. You can put them anywhere you want. If you choose not to use the reported extension_dir you'll simply need to specify the full path to the drivers.

  1. Extract the tar file you downloaded in step 1 and copy the .so files to the extension directory you determined in step 2. There are both threadsafe and non-threadsafe drivers. For a discussion about those, go here. You probably don't need both, but do whatever you like.
  2. Identify where PHP reads its configuration from:
$ php --ini
Configuration File (php.ini) Path: /usr/local/etc/php/7.4
Loaded Configuration File:         /usr/local/etc/php/7.4/php.ini
Scan for additional .ini files in: /usr/local/etc/php/7.4/conf.d  <=== We want this one
Additional .ini files parsed:      /usr/local/etc/php/7.4/conf.d/ext-opcache.ini
  1. Create a file named ext-sqlsrv.conf and place it in the directory listed above. Use PHP's rules (documented in the base php.ini file) for details on how to set yours. Here are a couple of examples:
# Example: Using a full path
$ echo -e "extension=/usr/local/lib/php/20190902/php_sqlsrv_74_nts.so\nextension=/usr/local/lib/php/20190902/php_pdo_sqlsrv_74_nts.so" >/usr/local/etc/php/7.4/conf.d/ext-sqlsrv.ini

# ----- OR -----

# Example: File is located in `extension_dir` and matches PHP's expected naming convention
$ mv /usr/local/lib/php/20190902/php_sqlsrv_74_nts.so /usr/local/lib/php/20190902/php_sqlsrv.so
$ mv /usr/local/lib/php/20190902/php_pdo_sqlsrv_74_nts.so /usr/local/lib/php/20190902/php_pdo_sqlsrv.so
$ echo -e "extension=sqlsrv\nextension=pdo_sqlsrv" >/usr/local/etc/php/7.4/conf.d/ext-sqlsrv.ini
  1. Check to verify that the sqlsrv and pdo_sqlsrv drivers are loaded:
$ php --info | grep 'sqlsrv support'
pdo_sqlsrv support => enabled
sqlsrv support => enabled

Thanks @nm777 for your info!

Yet, sqlsrv / pdo_sqlsrv depends on the ODBC driver, which does not officially support Big Sur either for the time being.

@yitam, that's a good point. However, for me I can say that the steps in the Microsoft docs (https://docs.microsoft.com/en-us/sql/connect/odbc/linux-mac/install-microsoft-odbc-driver-sql-server-macos?view=sql-server-ver15) for installing the ODBC drivers worked and in combination with the steps above, I'm able to query my local (docker-based) MSSQL instance from my PHP application.

Obviously in an unsupported configuration like this, others may have different results. I'm hoping my experience helps someone along the way.

Thanks @nm777 again for your contributions! This is in our priority list and we will get to it as soon as possible.

Thanks @nm777 ,

I followed the esxample you given but get following errors:

/usr/local/lib/php/pecl/20190902/sqlsrv.so: code signature in (/usr/local/lib/php/pecl/20190902/sqlsrv.so) not valid for use in process using Library Validation: library load disallowed by system policy)) in Unknown

Any idea how to solve this.

Thanks

I forgot that the first time I used the drivers I believe Mac's security kicked in. If you go to System Preferences >> Security & Privacy >> General, do you see a warning in the lower section about a blocked app? If so, click the button to allow it. You'll have to do this twice since there are 2 drivers.

I hope I'm not forgetting anything else....

Thanks @nm777

It workks

Thanks

Just released 5.9.0-beta2. This will be the last preview before the stable release. Even though we do not yet officially support Big Sur, pecl install should work as shown below.

sudo pecl install sqlsrv-5.9.0beta2
sudo pecl install pdo_sqlsrv-5.9.0beta2

Closing this issue due to inactivity. Please feel free to reopen this if necessary.

Found this issue looking for Big Sur help, and the beta install noted previously was almost successful, but I ran into this at the end:

Build process completed successfully
Installing '/usr/local/Cellar/php/8.0.1_1/pecl/20200930/pdo_sqlsrv.so'

Warning: mkdir(): File exists in System.php on line 294

Warning: mkdir(): File exists in /usr/local/Cellar/php/8.0.1_1/share/php/pear/System.php on line 294
ERROR: failed to mkdir /usr/local/Cellar/php/8.0.1_1/pecl/20200930

PHP

PHP 8.0.1 (cli) (built: Jan  8 2021 12:43:54) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.1, Copyright (c) Zend Technologies
    with Zend OPcache v8.0.1, Copyright (c), by Zend Technologies

PECL

PEAR Version: 1.10.12
PHP Version: 8.0.1
Zend Engine Version: 4.0.1
Running on: Darwin Macintarnation 20.2.0 Darwin Kernel Version 20.2.0: Wed Dec  2 20:39:59 PST 2020; root:xnu-7195.60.75~1/RELEASE_X86_64 x86_64

HOMEBREW

Homebrew 2.7.5
Homebrew/homebrew-core (git revision 3e9702; last commit 2021-01-15)
Homebrew/homebrew-cask (git revision bca5e; last commit 2021-01-15)

Any help would be greatly appreciated

Hi @justindantzer , this is a known issue with macOS install. Please check our FAQ Why pecl install fails on macOS with "Warning: mkdir(): File exists in System.php" message?

sudo pecl install sqlsrv-5.9.0beta2

I can install this library, but when running an error like this appears in Bigsur PHP 7.4.11

Exception Message:\n\nSQLSTATE[IMSSP]: This extension requires the Microsoft ODBC Driver for SQL Server to communicate with SQL Server. Access the following URL to download the ODBC Driver for SQL Server for x64: https:\/\/go.microsoft.com\/fwlink\/?LinkId=163712

Solved install
https://docs.microsoft.com/id-id/sql/connect/odbc/linux-mac/install-microsoft-odbc-driver-sql-server-macos?view=sql-server-ver15

Yes @armadeas. In case other people are looking for an answer to this, the ODBC driver is the prerequisite to sqlsrv or pdo_sqlsrv

Was this page helpful?
0 / 5 - 0 ratings