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

Created on 25 Apr 2017  路  27Comments  路  Source: microsoft/msphpsql

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

All 27 comments

@anderly We are looking into this. Are you able to use sqlcmd to connect to your SQL Server? Want to make sure the problem is not with with the ODBC Drivers being used under the hood. Also what taps do you see when you type brew tap

@meet-bhagdev yes, I'm able to use sqlcmd to connect to SQL Server. In my case, I'm connecting to a remote SQL Server in an Azure VM (not a local one via Docker).

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!

php -v output:

PHP 7.1.0 (cli) (built: Dec  2 2016 11:32:42) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.1.0-dev, Copyright (c) 1998-2016 Zend Technologies

find / -name sql.h output:

/opt/local/include/sql.h
/opt/local/var/macports/sources/rsync.macports.org/release/tarballs/base/src/cregistry/sql.h
/Users/adam/.rvm/src/MacPorts-2.2.1/src/cregistry/sql.h
/Users/adam/macports/var/macports/sources/rsync.macports.org/release/tarballs/base/src/cregistry/sql.h
/usr/local/Cellar/unixodbc/2.3.4/include/sql.h
/usr/local/include/sql.h

echo $PATH output:

/Users/adam/.dnx/runtimes/dnx-mono.1.0.0-beta4/bin:/opt/local/bin:/opt/local/sbin:/usr/local/share/python:/Users/adam/.rvm/gems/ruby-2.0.0-p353@railstutorial_rails_4.0/bin:/Users/adam/.rvm/gems/ruby-2.0.0-p353@global/bin:/Users/adam/.rvm/rubies/ruby-2.0.0-p353/bin:/usr/local/bin/github:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:~/bin:/opt/X11/bin:/usr/local/share/dotnet:/Library/Frameworks/Mono.framework/Versions/Current/Commands:/Users/adam/.rvm/bin:/usr/local/bin:~/.composer/vendor/bin

It looks like you have 'sql.h' in different places. They may or may not be the same, but your $PATH shows that /usr/local/bin is placed near the end. Please do:

  1. cat /etc/paths and check where /usr/local/bin is
  2. if the order from step 1 is different from the output of $PATH, check if there is a path variable override in ~/.bash_profile
  3. try moving /usr/local/bin near the beginning of $PATH and see if this helps PECL find 'sql.h'

For some information of why the order in the $PATH env variable is important, you can read this thread

Also out of curiosity, @anderly do you use any other ODBC/FreeTDS drivers?

I had previously used freetds, but uninstalled it.

I remembered I had installed some odbc and freetds stuff via MacPorts. Just removed all MacPorts packages and MacPorts itself.

Cleaned up my path. Now echo $PATH returns:

/Users/adam/.dnx/runtimes/dnx-mono.1.0.0-beta4/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:~/bin:/opt/X11/bin:/usr/local/share/dotnet:/Library/Frameworks/Mono.framework/Versions/Current/Commands:/Users/adam/.rvm/bin:~/.composer/vendor/bin

cat /etc/paths returns:

/usr/bin
/bin
/usr/sbin
/sbin
/usr/local/bin
~/bin

Tried sudo pecl install sqlsrv-4.1.7preview pdo_sqlsrv-4.1.7preview again, but same error about not finding sql.h.

Moved /usr/local/bin higher up in PATH so that echo $PATH now returns:

/Users/adam/.dnx/runtimes/dnx-mono.1.0.0-beta4/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:~/bin:/opt/X11/bin:/usr/local/share/dotnet:/Library/Frameworks/Mono.framework/Versions/Current/Commands:/Users/adam/.rvm/bin:~/.composer/vendor/bin:~/.composer/vendor/bin

Still no luck running above command. Not sure what else to try.

@anderly please do a few things:

  1. check if /usr/local/include/sql.h still exists
  2. is it the same as /usr/local/Cellar/unixodbc/2.3.4/include/sql.h
  3. type pecl version and check if it's the latest (PEAR Version 1.10.*)

I attempted to install PHP 7.1.* in a clean environment via Laravel Valet (https://laravel.com/docs/5.4/valet) , in which it says:
Install PHP 7.1 using Homebrew via brew install homebrew/php/php71

Note that this alone doesn't install PEAR/PECL.

I know you have taken some extreme measures by uninstalling, but take a look at the steps as outlined in our README. To use PECL you will need to install the current version.

  1. /usr/local/include/sql.h still exists: http://ander.ly/AisWQ
  2. It's a symlink to /usr/local/Cellar/unixodbc/2.3.4/include/sql.h
  3. pecl version returns:
PEAR Version: 1.10.1
PHP Version: 7.1.0
Zend Engine Version: 3.1.0-dev

Latest full log from sudo pecl install sqlsrv-4.1.7preview pdo_sqlsrv-4.1.7preview step: http://ander.ly/rdPYN+

Please try these:

echo 'export PATH="/usr/local/sbin:$PATH"' >> ~/.bash_profile
echo 'export PATH="/usr/local/bin:$PATH"' >> ~/.bash_profile

Ok, did above echo $PATH now returns:

/usr/local/bin:/usr/local/sbin:/Users/adam/.dnx/runtimes/dnx-mono.1.0.0-beta4/bin:/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:~/bin:/opt/X11/bin:/usr/local/share/dotnet:/Library/Frameworks/Mono.framework/Versions/Current/Commands:/Users/adam/.rvm/bin:~/.composer/vendor/bin

Tried install again in new terminal window, but same error.

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.

Thanks for the update. I'm trying to reproduce the problem in a clean env... which has PHP 5.6 as default.
FYI, we have fixed some bugs in MAC in the 4.1.8 preview version, so you might want to skip 4.1.7 preview

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!

@anderly Great news! @yitam is there a way we can detect what version is PECL/PEAR linked to?

Yeah, that's what I was thinking. I knew I had prior versions of PHP and my next thought was trying to determine what php version they were linked to.

Excellent!

try this pecl config-get php_bin

What's strange is I previously had PHP 7.1.0_11 and after reinstalling I now have 7.1.4_16. Both show in /usr/local/Cellar/php71/. php -v shows PHP 7.1.4. However, it looks like pecl installed the extension under /usr/local/Cellar/php71/7.1.0_11/lib/php/extensions not under my latest version.

For now, I just copied the extension over to /usr/local/Cellar/php71/7.1.4_16/lib/php/extensions.

Just saw your note above and running pecl config-get php_bin indeed returns /usr/local/Cellar/php71/7.1.0_11/bin/php. I hadn't run it previously, but my guess is it may have been returning the path to the PHP 5.6 version.

I'm able to connect to SQL Server after copying over the extension, but now I just need to get pear/pecl to point to my latest php version.

pecl config-set php_bin /usr/local/Cellar/php71/7.1.4_16/bin/php updated it to point to my latest version.

Yeah, that's the issue:

I might need to do a full brew uninstall of php71 to get rid of the old version.

pecl config-show still returns my old php path in several places:

Configuration (channel pecl.php.net):
=====================================
Auto-discover new Channels     auto_discover    <not set>
Default Channel                default_channel  pecl.php.net
HTTP Proxy Server Address      http_proxy       <not set>
PEAR server [DEPRECATED]       master_server    pear.php.net
Default Channel Mirror         preferred_mirror pecl.php.net
Remote Configuration File      remote_config    <not set>
PEAR executables directory     bin_dir          /usr/local/Cellar/php71/7.1.0_11/bin
PEAR documentation directory   doc_dir          /usr/local/Cellar/php71/7.1.0_11/lib/php/pear/docs
PHP extension directory        ext_dir          /usr/local/Cellar/php71/7.1.0_11/lib/php/extensions/no-debug-non-zts-20160303
PEAR directory                 php_dir          /usr/local/Cellar/php71/7.1.0_11/lib/php/pear
PEAR Installer cache directory cache_dir        /var/folders/6c/4xl0t5255h36zgp_481nt1580000gn/T//pear/cache
PEAR configuration file        cfg_dir          /usr/local/Cellar/php71/7.1.0_11/lib/php/pear/cfg
directory
PEAR data directory            data_dir         /usr/local/Cellar/php71/7.1.0_11/lib/php/pear/data
PEAR Installer download        download_dir     /var/folders/6c/4xl0t5255h36zgp_481nt1580000gn/T//pear/download
directory
Systems manpage files          man_dir          /usr/local/Cellar/php71/7.1.0_11/share/man
directory
PEAR metadata directory        metadata_dir     <not set>
PHP CLI/CGI binary             php_bin          /usr/local/Cellar/php71/7.1.4_16/bin/php
php.ini location               php_ini          <not set>
--program-prefix passed to     php_prefix       <not set>
PHP's ./configure
--program-suffix passed to     php_suffix       <not set>
PHP's ./configure
PEAR Installer temp directory  temp_dir         /var/folders/6c/4xl0t5255h36zgp_481nt1580000gn/T//pear/temp
PEAR test directory            test_dir         /usr/local/Cellar/php71/7.1.0_11/lib/php/pear/tests
PEAR www files directory       www_dir          /usr/local/Cellar/php71/7.1.0_11/lib/php/pear/www
Cache TimeToLive               cache_ttl        3600
Preferred Package State        preferred_state  stable
Unix file mask                 umask            22
Debug Log Level                verbose          1
PEAR password (for             password         <not set>
maintainers)
Signature Handling Program     sig_bin          /usr/local/bin/gpg
Signature Key Directory        sig_keydir       /usr/local/etc/php/7.1/pearkeys
Signature Key Id               sig_keyid        <not set>
Package Signature Type         sig_type         gpg
PEAR username (for             username         <not set>
maintainers)
User Configuration File        Filename         /Users/adam/.pearrc
System Configuration File      Filename         /usr/local/etc/php/7.1/pear.conf

@anderly, thanks for your patience. There are several things you can do.
brew unlink php56
and repeat for all previous PHPs you have installed.

Also, remove the old PHP 7.1 Cellar folder before reinstalling the latest PHP 7.1.4* --with-pear.

This page might give you some good ideas (even though it talks about PHP 5.6 or older).

Thanks @yitam. I'll give those a try. For now, I've got it working, but I'll try to clean things up a bit based on your recommendations. I think we can close the issue, unless you want to leave it open. Let me know.

Thanks again for your help!

@anderly Sounds good :) Closing this issue for now! If you have any other problems let us know.

Hi @anderly, there is a single step you can do in the future when you want to install the latest php 7.1.x
brew upgrade --cleanup php71
This will remove the previous versions of php 7.1.x already installed in your system. Hope this helps.

Thanks @yitam!

You're welcome @anderly. Hope it helps :)

Was this page helpful?
0 / 5 - 0 ratings