msphpsql: Mac install "fatal error: 'sql.h' file not found"

Trying to following install steps for Mac here under Step 2: https://www.microsoft.com/en-us/sql-server/developer-get-started/php-mac

  • Driver Version: sqlsrv-4.1.7preview pdo_sqlsrv-4.1.7preview
  • OS Version and Distro: macOS Sierra 10.12
  • Can you connect to SQL Server via sqlcmd: NO
  • Environment details: PHP 7.1.0 installed via Laravel Valet (https://laravel.com/docs/5.4/valet)

Steps to Reproduce:

brew tap microsoft/mssql-preview https://github.com/Microsoft/homebrew-mssql-preview
brew update
brew install unixodbc
brew install msodbcsql
brew install mssql-tools
brew install llvm --with-clang --with-clang-extra-tools
brew install autoconf
sudo pecl install sqlsrv-4.1.7preview pdo_sqlsrv-4.1.7preview
sudo echo "extension= pdo_sqlsrv.so" >> `php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||"`
sudo echo "extension= sqlsrv.so" >> `php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||"`

Receive the following error running sudo pecl install sqlsrv-4.1.7preview pdo_sqlsrv-4.1.7preview command: fatal error: 'sql.h' file not found

Full log from that step: http://ander.ly/A9Zr+

The sql.h file is indeed there: http://ander.ly/kMVV

Tried uninstalling all packages and installing again and unlinking unixodbc and relinking to no avail. Further info in this comment thread: https://www.microsoft.com/en-us/sql-server/developer-get-started/php-mac#comment-3272933953

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 1
  • Comments: 27 (13 by maintainers)

Most upvoted comments

So, redoing brew install homebrew/php/php71 fixed it. I’m wondering if the issue was that I had installed Laravel Valet prior to upgrading to macOS Sierra and then updating to Sierra may have put PHP 5.6 back in /usr/local/bin. So, while valet and laravel were working and command line were showing php version 7.1, I think pear/pecl were still trying to use 5.6.

Also, I installed the 4.1.8 version.

Thanks again for all the help troubleshooting!

Ok, so after adding /usr/local/bin to beginning of path, php -v returns 5.6 so it’s finding the default php included with MacOS. I’m retrying brew install php71 --with-pear to see if that corrects, but I may have to fully remove the 5.6 version since it may be conflicting.

Hi @anderly, I’m looking into this. In the meantime, could you please check a few things?

  1. Do you have any previous versions of PHP installed? Please check php -v
  2. Start a terminal and type find / -name sql.h

You should see something like these: /usr/local/Cellar/unixodbc/2.3.4/include/sql.h /usr/local/include/sql.h

Next, what’s the path echo $PATH
Thanks!