Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Install Driver PHP SQLSRV on Debian (Docker)

I have a PHP:8.1 Docker container that has always worked, and 1 week ago without modifying anything and trying to rebuild the image the instruction "pecl install sqlsrv" stopped working. Give error. If I make an error in this part of the code, the container is created normally.

Important! I tried to use a pure Debian docker image (only test), with nothing, nothing even the basics of Linux had, I installed everything by hand, when I tried to install sqlsrv and it gave the same error. So I don't think it's docker:php:8.1. I also tried with php:7.4 and earlier versions.

The log is very big but I'll put the final part that shows more information and the error:

...log...log...more log...p/ext/date/lib -I/tmp/pear/temp/sqlsrv/shared/  -DHAVE_CONFIG_H  -g -O2    -o sqlsrv.la -export-dynamic -avoid-version -prefer-pic -module -rpath /tmp/pear/temp/pear-build-defaultuserfcT8aJ/sqlsrv-5.10.1/modules  conn.lo util.lo init.lo stmt.lo shared/core_conn.lo shared/core_results.lo shared/core_stream.lo shared/core_init.lo shared/core_stmt.lo shared/core_util.lo shared/FormattedPrint.lo shared/localizationimpl.lo shared/StringFunctions.lo -Wl,-z,now -lstdc++ -lodbc -lodbcinst
libtool: link: warning: library `/usr/lib/x86_64-linux-gnu/libodbc.la' was moved.
grep: /usr/lib/x86_64-linux-gnu/libltdl.la: No such file or directory
/bin/sed: can't read /usr/lib/x86_64-linux-gnu/libltdl.la: No such file or directory
libtool: link: `/usr/lib/x86_64-linux-gnu/libltdl.la' is not a valid libtool archive
make: *** [Makefile:249: sqlsrv.la] Error 1
ERROR: `make' failed

Esse é meu arquivo dockerfile:

FROM php:8.1

# Get latest Composer
# COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

# Install dependecies
RUN apt-get update --fix-missing \
  && apt-get -y install cron git libicu-dev libonig-dev libzip-dev gnupg \
  unzip locales libpng-dev libxml2-dev nano wget software-properties-common supervisor

# Install Java 8
RUN mkdir -p /usr/share/man/man1 \
  && wget -qO - https://adoptopenjdk.jfrog.io/adoptopenjdk/api/gpg/key/public | apt-key add - \
  && add-apt-repository --yes https://adoptopenjdk.jfrog.io/adoptopenjdk/deb/ \
  && apt-get update && apt-get -y install adoptopenjdk-8-hotspot

# ...
RUN apt-get clean \
  && rm -rf /var/lib/apt/lists/* \
  && locale-gen en_US.UTF-8 \
  && localedef -f UTF-8 -i en_US en_US.UTF-8 \
  && mkdir /var/run/php-fpm

# Install SqlServer PHP driver
RUN cat /etc/os-release \
  && apt-get update \
  && curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - \
  && curl https://packages.microsoft.com/config/debian/11/prod.list \
      > /etc/apt/sources.list.d/mssql-release.list \
  && apt-get install -y --no-install-recommends apt-transport-https \
  && apt-get update \
  && ACCEPT_EULA=Y apt-get -y --no-install-recommends install  unixodbc-dev msodbcsql17

# Install PHP extensions
RUN docker-php-ext-install intl pdo_mysql zip bcmath mbstring exif pcntl bcmath gd \
  && pecl install sqlsrv pdo_sqlsrv \
  && docker-php-ext-enable sqlsrv pdo_sqlsrv

# App code location
WORKDIR /app

# Copy project files
COPY ./app/backend/smartsell-3-backend /app

# Copy crontab config file (To automatically run Laravel schedule/tasks)
RUN rm /etc/crontab \
  && cp /app/docker/crontab /etc/cron.d/fastmanager \
  && cp /app/docker/crontab /etc

# Copy supervisor config file (To automatically process Laravel jobs)
RUN cat /app/supervisord.conf > /etc/supervisor/supervisord.conf

# Install project dependencies
RUN composer install

# Expose container port
EXPOSE 8000

# Run server
CMD chmod 777 /app/entrypoint.sh; \
  /app/entrypoint.sh; \
  php artisan serve --host=0.0.0.0 --port=8000
like image 270
Dhenyson Jhean Avatar asked Jun 23 '26 07:06

Dhenyson Jhean


1 Answers

In my case, it was an error in the Microsoft repository, I found it in a recent forum talking about this bug. Alternatively install SQL from the Ubuntu repository (the image remains Debian).

So what changed was this:

# Install SqlServer PHP driver
RUN cat /etc/os-release \
  && apt-get update \
  && curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - \
  && curl https://packages.microsoft.com/config/ubuntu/22.04/prod.list \
      > /etc/apt/sources.list.d/mssql-release.list \
  && apt-get install -y --no-install-recommends apt-transport-https \
  && apt-get update \
  && ACCEPT_EULA=Y apt-get -y --no-install-recommends install unixodbc-dev msodbcsql17
like image 186
Dhenyson Jhean Avatar answered Jun 24 '26 20:06

Dhenyson Jhean



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!