在Debian上安装驱动程序PHP SQLSRV(Docker)

f1tvaqid  于 2023-03-01  发布在  Docker
关注(0)|答案(1)|浏览(207)

我有一个PHP:8.1 Docker容器,它一直工作,一周前,在没有修改任何东西和试图重建映像的情况下,指令“pecl install sqlsrv”停止工作。请给予错误。如果我在这部分代码中出错,容器将正常创建。

**重要!**我尝试使用纯Debian docker镜像(仅测试),没有任何东西,甚至Linux的基础都没有,我手动安装了所有东西,当我尝试安装sqlsrv时,它给出了相同的错误。所以我不认为它是docker:php:8.1。我也尝试了php:7.4和更早的版本。

日志非常大,但我会把显示更多信息和错误的最后一部分:

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

请输入文档文件:

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
kuuvgm7e

kuuvgm7e1#

必须同时安装unixodbcunixodbc-dev

# SQL Server
RUN wget https://packages.microsoft.com/keys/microsoft.asc && \
    apt-key add microsoft.asc && \
    curl https://packages.microsoft.com/config/debian/11/prod.list > /etc/apt/sources.list.d/mssql-release.list && \
    apt-get update && \
    ACCEPT_EULA=Y apt-get install -y --no-install-recommends \
    unixodbc \
    unixodbc-dev \
    msodbcsql17 \
    mssql-tools17

另一种方法是在启用ltdl的情况下从源安装ODBC驱动程序:

# UnixODBC
RUN wget ftp://ftp.unixodbc.org/pub/unixODBC/unixODBC-2.3.11.tar.gz && \
    tar -xzf unixODBC-2.3.11.tar.gz && \
    cd unixODBC-2.3.11 && \
    ./configure --enable-ltdl-install --prefix=/usr/local/unixODBC && \
    make && \
    make install

相关问题