ddev / ddev-contrib

Contrib space for DDEV services, tools, snippets, and approaches.
Apache License 2.0
162 stars 162 forks source link

SQL Server (Microsoft) install sqlsrv error #223

Closed robertoperuzzo closed 1 year ago

robertoperuzzo commented 1 year ago

Using the following Dockerfile in my project

ARG BASE_IMAGE
FROM $BASE_IMAGE

ENV PATH="${PATH}:/opt/mssql-tools/bin"
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y -o Dpkg::Options::="--force-confold" --no-install-recommends --no-install-suggests apt-utils curl gnupg2 ca-certificates

RUN curl -sSL -O https://packages.microsoft.com/keys/microsoft.asc
RUN apt-key add <microsoft.asc
RUN curl -sSL -o /etc/apt/sources.list.d/mssql-release.list https://packages.microsoft.com/config/debian/11/prod.list

RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y -o Dpkg::Options::="--force-confold" --no-install-recommends --no-install-suggests build-essential dialog php-pear php8.1-dev unixodbc-dev locales

RUN ACCEPT_EULA=Y DEBIAN_FRONTEND=noninteractive apt-get install -y msodbcsql18 mssql-tools

# Change the PHP version to what you want. It is currently set to version 8.0.
RUN pecl channel-update pecl.php.net
RUN pecl -d php_suffix=8.1 install sqlsrv
RUN pecl -d php_suffix=8.1 install pdo_sqlsrv

RUN echo 'extension=sqlsrv.so' >> "/etc/php/8.1/mods-available/sqlsrv.ini"
RUN echo 'extension=pdo_sqlsrv.so' >> "/etc/php/8.1/mods-available/pdo_sqlsrv.ini"

RUN phpenmod -v 8.1 sqlsrv pdo_sqlsrv

# Add AWS CLI.
RUN wget https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip -O awscliv2.zip
RUN unzip awscliv2.zip
RUN ./aws/install

I'm getting the error

❯ ddev debug refresh
failed to solve: executor failed running [/bin/sh -c pecl -d php_suffix=8.1 install sqlsrv]: exit code: 1
...
...
...
#22 18.22 /bin/sed: can't read /usr/lib/x86_64-linux-gnu/libltdl.la: No such file or directory
#22 18.22 libtool:   error: '/usr/lib/x86_64-linux-gnu/libltdl.la' is not a valid libtool archive
#22 18.22 make: *** [Makefile:250: sqlsrv.la] Error 1
#22 18.23 ERROR: `make' failed
...
...

It seems something related to unixodbc 2.3.11, because using the 2.3.7 like that

RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y -o Dpkg::Options::="--force-confold" --no-install-recommends --no-install-suggests \
    build-essential \
    dialog \
    php-pear \
    php8.1-dev \
    unixodbc=2.3.7 \
    odbcinst=2.3.7 \
    odbcinst1debian2=2.3.7 \
    unixodbc-dev=2.3.7 \
    locales

the docker image is built correctly.

rfay commented 1 year ago

Hi @robertoperuzzo I'm afraid if you're on an M1 mac, (looks like it?) I think you're out of look; there are no resources for sqlsrv for the arm64 architecture AFAIK.

robertoperuzzo commented 1 year ago

Hi @robertoperuzzo I'm afraid if you're on an M1 mac, (looks like it?) I think you're out of look; there are no resources for sqlsrv for the arm64 architecture AFAIK.

Fortunately I'm on Intel mac 2,3 GHz 8-Core Intel Core i9, so probably I will have a chance ;)

As a matter of fact, with the following Dockerfile I have the pdo_sqlsrv installed and working.

ARG BASE_IMAGE
FROM $BASE_IMAGE

ENV PATH="${PATH}:/opt/mssql-tools/bin"
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y -o Dpkg::Options::="--force-confold" --no-install-recommends --no-install-suggests apt-utils curl gnupg2 ca-certificates

RUN curl -sSL -O https://packages.microsoft.com/keys/microsoft.asc
RUN apt-key add <microsoft.asc
RUN curl -sSL -o /etc/apt/sources.list.d/mssql-release.list https://packages.microsoft.com/config/debian/11/prod.list

RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y -o Dpkg::Options::="--force-confold" --no-install-recommends --no-install-suggests \
    build-essential \
    dialog \
    php-pear \
    php8.1-dev \
    unixodbc=2.3.7 \
    odbcinst=2.3.7 \
    odbcinst1debian2=2.3.7 \
    unixodbc-dev=2.3.7 \
    locales

RUN ACCEPT_EULA=Y DEBIAN_FRONTEND=noninteractive apt-get install -y msodbcsql18 mssql-tools

# Change the PHP version to what you want. It is currently set to version 8.0.
RUN pecl channel-update pecl.php.net
RUN pecl -d php_suffix=8.1 install sqlsrv
RUN pecl -d php_suffix=8.1 install pdo_sqlsrv

RUN echo 'extension=sqlsrv.so' >> "/etc/php/8.1/mods-available/sqlsrv.ini"
RUN echo 'extension=pdo_sqlsrv.so' >> "/etc/php/8.1/mods-available/pdo_sqlsrv.ini"

RUN phpenmod -v 8.1 sqlsrv pdo_sqlsrv
rfay commented 1 year ago

Please do a PR to the existing recipe then, thanks.

Note that you don't have to explicitly set the PHP version, as you can now use the variable $DDEV_PHP_VERSION in .ddev/web-build/Dockerfile; also, the ARGs at the top are no longer needed.

robertoperuzzo commented 1 year ago

@rfay we have the first release of add-on https://github.com/robertoperuzzo/ddev-sqlsrv

rfay commented 1 year ago

Awesome!

robertoperuzzo commented 1 year ago

I close this issue because it is preferable to use the add-on.