Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 301
dlove Avatar asked Sep 08 '25 14:09

dlove


2 Answers

I fixed the problem by installing the following package versions:

apt-get install unixodbc-dev=2.3.7 unixodbc=2.3.7 odbcinst1debian2=2.3.7 odbcinst=2.3.7

Use this until the bug gets resolved.

Source: https://github.com/microsoft/linux-package-repositories/issues/36

like image 195
Abraham Araujo Moreno Avatar answered Sep 10 '25 06:09

Abraham Araujo Moreno


HI I had the same issue I could build it literally four days ago then it gave the error, I then upgraded my pyodbc from version 4.0.32 to the latest version 4.0.35, then it worked

like image 20
jeremy Avatar answered Sep 10 '25 05:09

jeremy