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
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
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
just happens today with php:7.3-fpm-buster, Changing the Debian list from 10 to 9 resolve it
From
To
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.
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:
FROM php:[version]-apache
toFROM php:[version]-apache-buster
(FROM php:8.1-apache-buster
)RUN curl https://packages.microsoft.com/config/debian/11/prod.list > /etc/apt/sources.list.d/mssql-release.list
toRUN curl https://packages.microsoft.com/config/debian/9/prod.list > /etc/apt/sources.list.d/mssql-release.list
I fixed the problem by installing the following package versions:
Use this until the bug gets resolved.
Source: https://github.com/microsoft/linux-package-repositories/issues/36
This worked for me
ubuntu 22.04