phpsql-serverdockersqlsrvfpm

Docker: unixodbc.h no such file or directory. "pecl install sqlsrv" error with unixodbc-dev already installed


This had been working up until a few days ago. We are building a docker container with the following code, but this is the error that happens when trying to "pecl install sqlsrv". Trying to connect to mssql server from PHP in this container. Anyone out there smarter than me have any ideas?

Docker File:

FROM  --platform=linux/amd64 php:8.0-fpm

RUN apt-get update && apt-get -y install nano apt-utils libxml2-dev gnupg \
    && apt-get install -y zlib1g-dev \
    && apt-get install -y libzip-dev \
    && docker-php-ext-install zip 

RUN apt-get -y install libicu-dev gcc g++ make autoconf libc-dev pkg-config libssl-dev apt-transport-https libgss3 

# Install MS ODBC Driver for SQL Server
RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - \
    && curl https://packages.microsoft.com/config/debian/10/prod.list > /etc/apt/sources.list.d/mssql-release.list \
    && apt-get update

# Automatically accept the terms from Microsoft
RUN apt-get install -y unixodbc unixodbc-dev odbcinst locales
RUN ACCEPT_EULA=Y apt-get install -y msodbcsql17
RUN apt-get -y install gcc g++ make autoconf libc-dev pkg-config
RUN apt-get update 
RUN pecl install sqlsrv
RUN pecl install pdo_sqlsrv
RUN docker-php-ext-enable sqlsrv pdo_sqlsrv

Error:

#0 41.16 In file included from /usr/include/sql.h:19,
#0 41.16                  from /tmp/pear/temp/sqlsrv/shared/xplat.h:30,
#0 41.16                  from /tmp/pear/temp/sqlsrv/shared/typedefs_for_linux.h:23,
#0 41.16                  from /tmp/pear/temp/sqlsrv/shared/xplat_winnls.h:24,
#0 41.16                  from /tmp/pear/temp/sqlsrv/shared/FormattedPrint.h:24,
#0 41.16                  from /tmp/pear/temp/sqlsrv/shared/core_sqlsrv.h:41,
#0 41.16                  from /tmp/pear/temp/sqlsrv/php_sqlsrv_int.h:25,
#0 41.16                  from /tmp/pear/temp/sqlsrv/conn.cpp:24:
#0 41.16 /usr/include/sqltypes.h:56:10: fatal error: unixodbc.h: No such file or directory
#0 41.16    56 | #include "unixodbc.h"
#0 41.16       |          ^~~~~~~~~~~~
#0 41.16 compilation terminated.
#0 41.18 make: *** [Makefile:209: conn.lo] Error 1
#0 41.19 ERROR: `make' failed

I have tried every version of PHP from 7.0 up to 8.1 with or without fpm. I have also tried several versions of msodbcsql and unixodbc/unixodbc-dev and several versions of sqlsrv and pdo_sqlsrv.


Solution

  • This issue is happening with Debian 10 and 11 with Drive 5.10.0 or 5.10.1

    With driver 5.9.0 and Debian 10, PHP 7.4 but repo microsoft debian 9. Its Works !!

    In Debian 10, with php 8.1 changing the repository from Debian 10 to Debian 9. It will create the Docker script, I haven't tested if it will connect to the database, I believe so.

    Change https://packages.microsoft.com/config/debian/10/prod.list to https://packages.microsoft.com/config/debian/9/prod.list