Get sql.h file not found when install SQLSRV driver for macOS Monterey

Angela Chan 21 Reputation points
2022-01-17T17:17:42.017+00:00

I have macOS Monterey (M1 Pro), and would like to install sqlsrv and pdo_sqlsrv for connecting my php application (php7.4 laravel) to SQLserver DB. I follow https://www.microsoft.com/en-us/sql-server/developer-get-started/php/mac/?rtc=1 to install the environment. However, when I do sudo pecl install sqlsrv, I got the following error

  ...
configure: patching config.h.in
configure: creating ./config.status
config.status: creating config.h
running: make
/bin/sh /private/tmp/pear/temp/pear-build-rootmUMiMZ/sqlsrv-5.10.0beta2/libtool --mode=compile g++ -std=c++11 -I. -I/private/tmp/pear/temp/sqlsrv -DPHP_ATOM_INC -I/private/tmp/pear/temp/pear-build-rootmUMiMZ/sqlsrv-5.10.0beta2/include -I/private/tmp/pear/temp/pear-build-rootmUMiMZ/sqlsrv-5.10.0beta2/main -I/private/tmp/pear/temp/sqlsrv -I/opt/homebrew/Cellar/php@7.4/7.4.27/include/php -I/opt/homebrew/Cellar/php@7.4/7.4.27/include/php/main -I/opt/homebrew/Cellar/php@7.4/7.4.27/include/php/TSRM -I/opt/homebrew/Cellar/php@7.4/7.4.27/include/php/Zend -I/opt/homebrew/Cellar/php@7.4/7.4.27/include/php/ext -I/opt/homebrew/Cellar/php@7.4/7.4.27/include/php/ext/date/lib -I/private/tmp/pear/temp/sqlsrv/shared/  -DHAVE_CONFIG_H  -std=c++11 -D_FORTIFY_SOURCE=2 -O2 -fstack-protector   -c /private/tmp/pear/temp/sqlsrv/conn.cpp -o conn.lo
mkdir .libs
 g++ -std=c++11 -I. -I/private/tmp/pear/temp/sqlsrv -DPHP_ATOM_INC -I/private/tmp/pear/temp/pear-build-rootmUMiMZ/sqlsrv-5.10.0beta2/include -I/private/tmp/pear/temp/pear-build-rootmUMiMZ/sqlsrv-5.10.0beta2/main -I/private/tmp/pear/temp/sqlsrv -I/opt/homebrew/Cellar/php@7.4/7.4.27/include/php -I/opt/homebrew/Cellar/php@7.4/7.4.27/include/php/main -I/opt/homebrew/Cellar/php@7.4/7.4.27/include/php/TSRM -I/opt/homebrew/Cellar/php@7.4/7.4.27/include/php/Zend -I/opt/homebrew/Cellar/php@7.4/7.4.27/include/php/ext -I/opt/homebrew/Cellar/php@7.4/7.4.27/include/php/ext/date/lib -I/private/tmp/pear/temp/sqlsrv/shared/ -DHAVE_CONFIG_H -std=c++11 -D_FORTIFY_SOURCE=2 -O2 -fstack-protector -c /private/tmp/pear/temp/sqlsrv/conn.cpp  -fno-common -DPIC -o .libs/conn.o
In file included from /private/tmp/pear/temp/sqlsrv/conn.cpp:24:
In file included from /private/tmp/pear/temp/sqlsrv/php_sqlsrv_int.h:25:
In file included from /private/tmp/pear/temp/sqlsrv/shared/core_sqlsrv.h:41:
In file included from /private/tmp/pear/temp/sqlsrv/shared/FormattedPrint.h:24:
In file included from /private/tmp/pear/temp/sqlsrv/shared/xplat_winnls.h:24:
In file included from /private/tmp/pear/temp/sqlsrv/shared/typedefs_for_linux.h:23:
/private/tmp/pear/temp/sqlsrv/shared/xplat.h:30:10: fatal error: 'sql.h' file not found
#include <sql.h>
         ^~~~~~~
1 error generated.
make: *** [conn.lo] Error 1
ERROR: `make' failed

I also follow https://github.com/microsoft/msphpsql/issues/373 to check $path

local % pecl config-show
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          /opt/homebrew/opt/php@7.4/bin
PEAR documentation directory   doc_dir          /opt/homebrew/share/pear@7.4/doc
PHP extension directory        ext_dir          /opt/homebrew/lib/php/pecl/20190902
PEAR directory                 php_dir          /opt/homebrew/share/pear@7.4
PEAR Installer cache directory cache_dir        /private/tmp/pear/cache
PEAR configuration file        cfg_dir          /opt/homebrew/share/pear@7.4/cfg
directory
PEAR data directory            data_dir         /opt/homebrew/share/pear@7.4/data
PEAR Installer download        download_dir     /private/tmp/pear/download
directory
Systems manpage files          man_dir          /opt/homebrew/share/man
directory
PEAR metadata directory        metadata_dir     <not set>
PHP CLI/CGI binary             php_bin          /opt/homebrew/opt/php@7.4/bin/php
php.ini location               php_ini          /opt/homebrew/etc/php/7.4/php.ini
--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         /private/tmp/pear/temp
PEAR test directory            test_dir         /opt/homebrew/share/pear@7.4/test
PEAR www files directory       www_dir          /opt/homebrew/share/pear@7.4/htdocs
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       /opt/homebrew/etc/php/7.4/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/angelachan-tactile/.pearrc
System Configuration File      Filename         /opt/homebrew/etc/php/7.4/pear.conf

on echo $path :

/opt/homebrew/opt/php@7.4/sbin /opt/homebrew/opt/php@7.4/bin /opt/homebrew/bin /opt/homebrew/sbin /usr/local/bin /usr/bin /bin /usr/sbin /sbin

on find / -name sql.h:

/opt/homebrew/include/sql.h
/opt/homebrew/Cellar/unixodbc/2.3.9_1/include/sql.h

Did I miss any configuration to install sqlsrv and pdo_sqsrv?

Thanks

SQL Server | Other
0 comments No comments
{count} votes

Accepted answer
  1. George Nagy 156 Reputation points
    2022-01-19T20:40:54.513+00:00

    This page contained a solution that worked for me:

    https://github.com/microsoft/msphpsql/issues/651

    Specifically, adjusting the build commands to look like this:

    sudo CXXFLAGS="-I/opt/homebrew/opt/unixodbc/include/" LDFLAGS="-L/opt/homebrew/lib/" pecl install sqlsrv
    sudo CXXFLAGS="-I/opt/homebrew/opt/unixodbc/include/" LDFLAGS="-L/opt/homebrew/lib/" pecl install pdo_sqlsrv
    

    For MAMP users, the commands may look like this (if pecl is not in the PATH)

    sudo CXXFLAGS="-I/opt/homebrew/opt/unixodbc/include/" LDFLAGS="-L/opt/homebrew/lib/" /Applications/MAMP/bin/php/php7.4.21/bin/pecl install sqlsrv
    sudo CXXFLAGS="-I/opt/homebrew/opt/unixodbc/include/" LDFLAGS="-L/opt/homebrew/lib/" /Applications/MAMP/bin/php/php7.4.21/bin/pecl install pdo_sqlsrv
    

    The above assume that the 'unixodbc' package is already installed. If not, it can be installed with:

    brew install unixodbc
    

4 additional answers

Sort by: Most helpful
  1. Paolo Cecchetti 1 Reputation point
    2022-01-19T07:30:26.087+00:00

    I have the same issue

    0 comments No comments

  2. Paolo Cecchetti 1 Reputation point
    2022-01-19T21:02:08.65+00:00

    anonymous user-3704 thanks so much. It worked like a charm!
    Compiled and tested over a remote server on a VPN, worst case scenario :-)


  3. Angela Chan 21 Reputation points
    2022-01-20T03:41:30.25+00:00

    anonymous user-3704 Thanks for your help. It works on my installation.

    0 comments No comments

  4. alukxsPH 1 Reputation point
    2022-02-20T16:53:23+00:00

    anonymous user-3704. Thanks mate! You are godsent! :D

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.