gpt4 book ai didi

php - 带有SQLSRV驱动程序错误的Docker PHP-FPM Alpine

转载 作者:行者123 更新时间:2023-12-02 19:21:09 27 4
gpt4 key购买 nike

当我尝试连接到sqlserver数据库时出现此错误:

Array ( [0] => Array ( [0] => IMSSP [SQLSTATE] => IMSSP [1] => -49 [code] => -49 [2] => This extension 
requires the Microsoft ODBC Driver for SQL Server. Access the following URL to download the ODBC
Driver for SQL Server for x64: https://go.microsoft.com/fwlink/?LinkId=163712 [message] => This
extension requires the Microsoft ODBC Driver for SQL Server. Access the following URL to download the
ODBC Driver for SQL Server for x64: https://go.microsoft.com/fwlink/?LinkId=163712 ) )

我的Dockerfile如下:
FROM microsoft/mssql-tools as mssql
FROM php:7.2-fpm-alpine

COPY --from=mssql /opt/microsoft/ /opt/microsoft/
COPY --from=mssql /opt/mssql-tools/ /opt/mssql-tools/
COPY --from=mssql /usr/lib/libmsodbcsql-13.so /usr/lib/libmsodbcsql-13.so

RUN apk update \
&& apk add --no-cache git mysql-client curl libmcrypt libmcrypt-dev openssh-client icu-dev
unixodbc-dev \
libxml2-dev freetype-dev libpng-dev libjpeg-turbo-dev g++ make autoconf \
&& docker-php-source extract \
&& pecl install xdebug redis \
&& docker-php-ext-enable xdebug redis \
&& docker-php-source delete \
&& docker-php-ext-install pdo_mysql soap intl zip \
&& pecl install \
sqlsrv \
pdo_sqlsrv \
&& docker-php-ext-enable --ini-name 30-sqlsrv.ini sqlsrv \
&& docker-php-ext-enable --ini-name 35-pdo_sqlsrv.ini pdo_sqlsrv \
&& echo "xdebug.remote_enable=on" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
&& echo "xdebug.remote_autostart=off" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
&& echo "xdebug.remote_port=10000" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
&& echo "xdebug.remote_handler=dbgp" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
&& echo "xdebug.remote_connect_back=0" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
#&& curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer \
&& rm -rf /tmp/*

CMD ["php-fpm", "-F"]

WORKDIR /var/www/cssp

EXPOSE 9000

似乎驱动程序的安装有问题
有人尝试过吗?请分享。谢谢。

最佳答案

在下面尝试使用DockerFile

FROM microsoft/mssql-tools as mssql
FROM php:7.2-fpm-alpine

COPY --from=mssql /opt/microsoft/ /opt/microsoft/
COPY --from=mssql /opt/mssql-tools/ /opt/mssql-tools/
COPY --from=mssql /usr/lib/libmsodbcsql-13.so /usr/lib/libmsodbcsql-13.so

# Install language pack
ENV MUSL_LOCALE_DEPS cmake make musl-dev gcc gettext-dev libintl
ENV MUSL_LOCPATH /usr/share/i18n/locales/musl

RUN apk add --no-cache \
$MUSL_LOCALE_DEPS \
&& wget https://gitlab.com/rilian-la-te/musl-locales/-/archive/master/musl-locales-master.zip \
&& unzip musl-locales-master.zip \
&& cd musl-locales-master \
&& cmake -DLOCALE_PROFILE=OFF -D CMAKE_INSTALL_PREFIX:PATH=/usr . && make && make install \
&& cd .. && rm -r musl-locales-master

# --- not show here---

# mssql odbc for dabase connection
RUN curl -O https://download.microsoft.com/download/e/4/e/e4e67866-dffd-428c-aac7-8d28ddafb39b/msodbcsql17_17.5.2.1-1_amd64.apk
RUN curl -O https://download.microsoft.com/download/e/4/e/e4e67866-dffd-428c-aac7-8d28ddafb39b/mssql-tools_17.5.2.1-1_amd64.apk
RUN apk add --allow-untrusted msodbcsql17_17.5.2.1-1_amd64.apk
RUN apk add --allow-untrusted mssql-tools_17.5.2.1-1_amd64.apk

RUN set -xe \
&& apk add --no-cache --virtual .persistent-deps freetds unixodbc \
&& apk add --no-cache --virtual .build-deps $PHPIZE_DEPS unixodbc-dev freetds-dev \
&& docker-php-source extract \
&& docker-php-ext-install pdo_dblib \
&& pecl install sqlsrv pdo_sqlsrv \
&& docker-php-ext-enable --ini-name 30-sqlsrv.ini sqlsrv \
&& docker-php-ext-enable --ini-name 35-pdo_sqlsrv.ini pdo_sqlsrv \
&& docker-php-source delete \
&& apk del .build-deps

关于php - 带有SQLSRV驱动程序错误的Docker PHP-FPM Alpine,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59621389/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com