skip to Main Content

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.

7

Answers


  1. 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

    Login or Signup to reply.
  2. 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

    Login or Signup to reply.
  3. just happens today with php:7.3-fpm-buster, Changing the Debian list from 10 to 9 resolve it

    From

    curl https://packages.microsoft.com/config/debian/10/prod.list > /etc/apt/sources.list.d/mssql-release.list

    To

    curl https://packages.microsoft.com/config/debian/9/prod.list > /etc/apt/sources.list.d/mssql-release.list

    Login or Signup to reply.
  4. I’ve had the same issue the last several days. Based on others’ suggestions here, I’ve managed to get the box to build by downgrading debian core from bullseye to buster (11 -> 10) and changing the debian ver to 9 in the packages list url as noted in other replies.

    I had attempted to simply specify an older driver (5.9.0) while still running bullseye to no avail.

    It does appear to still be using driver 5.10.1 successfully under buster w/ stretch sources list. I’m running php 8.2 FWIW.

    Given the sudden appearance of this issue, I expect a fix will be in the works. If I learn anything new I’ll amend this response, and hopefully I can revert to bullseye in the next few days. For now this seems to suffice to fix my pipeline.

    Login or Signup to reply.
  5. If you are using the PHP Official Docker image with Apache, the changes you need to make to downgrade to Buster and get the correct packages list as recommended in other answers are:

    1. At the top, change FROM php:[version]-apache to FROM php:[version]-apache-buster (FROM php:8.1-apache-buster)
    2. Change RUN curl https://packages.microsoft.com/config/debian/11/prod.list > /etc/apt/sources.list.d/mssql-release.list to RUN curl https://packages.microsoft.com/config/debian/9/prod.list > /etc/apt/sources.list.d/mssql-release.list
    Login or Signup to reply.
  6. 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

    Login or Signup to reply.
  7. This worked for me
    ubuntu 22.04

    RUN ACCEPT_EULA=Y apt-get install -y 
        msodbcsql17 
        mssql-tools 
        unixodbc-dev=2.3.7 
        unixodbc=2.3.7 
        odbcinst1debian2=2.3.7 
        odbcinst=2.3.7
    
    RUN echo 'export PATH="$PATH:/opt/mssql-tools17/bin"' >> ~/.bashrc
    RUN exec bash
    
    RUN pecl install sqlsrv-5.8.0
    RUN printf "; priority=20nextension=sqlsrv.son" > /etc/php/7.3/mods-available/sqlsrv.ini
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search