Этот ответ для ddev v1.11.0.
Добавьте это Dockerfile
к .ddev/web-build
:
ARG BASE_IMAGE=drud/ddev-webserver:v1.11.0
FROM $BASE_IMAGE
COPY install_sqlsrv.sh /tmp/
RUN /bin/bash -c /tmp/install_sqlsrv.sh > /tmp/buildoutput.log 2>&1 && rm /tmp/install_sqlsrv.sh
И сохраните этот скрипт как install_sqlsrv.sh
к .ddev/.webimageBuild
(примечание: НЕ тот же каталог! .ddev/web-build
это не каталог, из которого ddev создает окончательный образ):
#!/bin/bash
# This script installs MSSQL server. Contains some ddev-specific tweaks:
# - doesn't add ondrej's repo because that's already added
# - doesn't source .bashrc because that will happen anyway.
# - doesn't restart Apache; it's not started at this point.
# - assumes it's being run under sudo anyway and doesn't use sudo or su or exit
# - tries to run apt update as few times as possible
# - Apache's mpm_event module is already disabled.
# Those don't work well with Docker builds.
# https://docs.microsoft.com/en-us/sql/connect/php/installation-tutorial-linux-mac?view=sql-server-2017#step-1-install-php-2
# Some of these packages will be redundant.
export DEBIAN_FRONTEND=noninteractive
# Install sqlsrv drivers.
export PHP_VERSIONS="php7.0 php7.1 php7.2 php7.3"
# Note: Only works for PHP 7.0+.
export PHP_SUFFIXES="7.0 7.1 7.2 7.3"
# https://docs.microsoft.com/en-us/sql/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server?view=sql-server-2017
curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
#Download appropriate package for the OS version
#Choose only ONE of the following, corresponding to your OS version
#Debian 9
curl https://packages.microsoft.com/config/debian/9/prod.list >/etc/apt/sources.list.d/mssql-release.list &&
apt-get update
apt-get install -y curl apt-transport-https
for v in $PHP_VERSIONS; do
apt-get install -y "$v" "$v"-dev "$v"-xml
done
ACCEPT_EULA=Y apt-get install -y msodbcsql17
# optional: for bcp and sqlcmd
ACCEPT_EULA=Y apt-get install -y mssql-tools
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >>~/.bash_profile
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >>~/.bashrc
# optional: for unixODBC development headers
apt-get install -y unixodbc-dev
# https://docs.microsoft.com/en-us/sql/connect/php/installation-tutorial-linux-mac?view=sql-server-2017#step-3-install-the-php-drivers-for-microsoft-sql-server
# See https://stackoverflow.com/questions/40419718/how-to-install-php-extension-using-pecl-for-specific-php-version-when-several-p/48352487
for v in $PHP_SUFFIXES; do
pecl -d php_suffix="$v" install sqlsrv
pecl -d php_suffix="$v" install pdo_sqlsrv
# This does not remove the extensions; it just removes the metadata that says
# the extensions are installed.
pecl uninstall -r sqlsrv
pecl uninstall -r pdo_sqlsrv
done
for v in $PHP_SUFFIXES; do
printf "; priority=20\nextension=sqlsrv.so\n" >/etc/php/"$v"/mods-available/sqlsrv.ini
printf "; priority=30\nextension=pdo_sqlsrv.so\n" >/etc/php/"$v"/mods-available/pdo_sqlsrv.ini
chmod 666 /etc/php/"$v"/mods-available/*sqlsrv*.ini
done
phpenmod sqlsrv pdo_sqlsrv
# Step 4 skipped because Apache is already configured.
# Step 5 skipped because Apache is not started at this point.
# Reduce image size some.
rm -rf /var/lib/apt/lists/*
Затем просто запустите ddev start
еще раз.
Примечание: Сборка может занять пару минут.Вы можете ускорить его, удалив версии PHP, которые вы не используете, из двух переменных в верхней части скрипта Bash.
См. Комментарии в скриптах, чтобы узнать, откуда пришли инструкции и как они были изменены.работа с ddev.