How to deal with fatal error: sql.h: No such file or directory when installing pecl sqlsrv

Background

Whilst following Microsoft’s official instructions on how to install SQL Server for PHP, you might encounter the following problem:

/tmp/pear/temp/sqlsrv/shared/xplat.h:30:10: fatal error: sql.h: No such file or directory
#include <sql.h>
^~~~~~~
compilation terminated.
Makefile:194: recipe for target 'conn.lo' failed
make: *** [conn.lo] Error 1
ERROR: `make' failed

Solution

The Microsoft ODBC driver’s installation page mentions that the development libraries are optional – they are not. So run the command below to get it working:

sudo apt-get install unixodbc-dev

Reference

https://docs.microsoft.com/en-us/sql/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server?view=sql-server-ver15

Share this article

1 thought on “How to deal with fatal error: sql.h: No such file or directory when installing pecl sqlsrv”

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to Top