microsoft / msphpsql

Microsoft Drivers for PHP for SQL Server
MIT License
1.8k stars 373 forks source link

Error when installing sqlsrv and pdo_sqlsrv in php8+ apache docker image #1438

Open andremartinez opened 1 year ago

andremartinez commented 1 year ago

PHP version
Tested for PHP within docker images php:8.1-apache and php:8.2-apache

PHP SQLSRV or PDO_SQLSRV version
Both stable (5.10.1) sqlsrv pdo_sqlsrv and beta (5.11.0beta1) sqlsrv pdo_sqlsrv

Microsoft ODBC Driver version
Versions msodbcsql18 and msodbcsql17 for ubuntu/20.04

Problem description
Installation in a Dockerfile using pecl is failing with the following message:

#0 15.28 libtool: link: warning: library `/usr/lib/x86_64-linux-gnu/libodbc.la' was moved.
#0 15.29 grep: /usr/lib/x86_64-linux-gnu/libltdl.la: No such file or directory
#0 15.29 /bin/sed: can't read /usr/lib/x86_64-linux-gnu/libltdl.la: No such file or directory
#0 15.29 libtool: link: `/usr/lib/x86_64-linux-gnu/libltdl.la' is not a valid libtool archive
#0 15.29 make: *** [Makefile:251: sqlsrv.la] Error 1
#0 15.29 ERROR: `make' failed
------
Dockerfile:28
--------------------
  26 |     # # Required extensions
  27 |     RUN docker-php-ext-install pdo intl gd mbstring zip
  28 | >>> RUN pecl install sqlsrv
  29 |     RUN pecl install pdo_sqlsrv
  30 |     RUN docker-php-ext-enable sqlsrv pdo_sqlsrv
--------------------
ERROR: failed to solve: process "/bin/sh -c pecl install sqlsrv" did not complete successfully: exit code: 1
ERROR: Service 'server' failed to build : Build failed

This problem is very likely to be related to the issue https://github.com/microsoft/msphpsql/issues/1436 as the workaround mentioned there (using specific versions for some libraries) works for me as well

Expected behavior and actual behavior
Another test I ran was to try and compile the extension, the steps were:

  1. Run the php:8.1-apache docker image, and get into it using exec to bash
  2. Download the source code for the sqlsrv module and unzip it.
  3. apt-get update && apt-get install -y unixodbc-dev libltdl-dev libodbc1
  4. cd into the pdo_sqlsrv-5.10.1 directory (the source code)
  5. Run the phpize command to generate the necessary build files.
  6. Run the ./configure script to configure the build options.
  7. Run the make command to compile the module

The error message at this point is exactly the same.

Repro code or steps to reproduce

Create a Dockerfile with the following content then build it:

FROM php:8.1-apache

ARG ENV
ENV ENV=${ENV:-production}

# Instala Dependencias
RUN apt-get update \
&& apt-get install -y curl git unzip libpq-dev libicu-dev libzip-dev gnupg \
zlib1g-dev g++ libpng-dev libonig-dev unixodbc-dev \
&& curl -s https://getcomposer.org/installer > composer_installer.php && \ 
php composer_installer.php \
&& mv composer.phar /usr/local/bin/composer && \
rm composer_installer.php

# Microsoft SQL Server Drivers & Tools
RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
RUN curl https://packages.microsoft.com/config/ubuntu/20.04/prod.list > /etc/apt/sources.list.d/mssql-release.list
RUN apt-get update && ACCEPT_EULA=Y apt-get install -y msodbcsql18 \
    && ACCEPT_EULA=Y apt-get install -y mssql-tools18 \
    && echo 'export PATH="$PATH:/opt/mssql-tools18/bin"' >> ~/.bashrc \
    source ~/.bashrc
# Required extensions
RUN docker-php-ext-install pdo intl gd mbstring zip \
    && pecl install sqlsrv pdo_sqlsrv  \
    && docker-php-ext-enable sqlsrv pdo_sqlsrv 
docker build . 
v-makouz commented 1 year ago

I'm not sure what's happening at a glance, but does /usr/lib/x86_64-linux-gnu/libltdl.la exist? And if so, what are the contents of it? If it doesn't then there maybe some issue with libltdl-dev installation (it's supposed to come from that package)

andremartinez commented 1 year ago

Hello @v-makouz , answering:

I'm not sure what's happening at a glance, but does /usr/lib/x86_64-linux-gnu/libltdl.la exist? And if so, what are the contents of it?

I double checked it now, and no It's not present

If it doesn't then there maybe some issue with libltdl-dev installation (it's supposed to come from that package)

I tried the workaround suggested here (#1436 installing the version 2.3.7 of unixodbc-dev) and it worked, so my guess is that this library installs libltdl-dev and the most recent version of either of them got rid of .la files.

What I have no idea about is how these files are related to the process of compiling sqlsrv and pdo_sqlsrv, but as I said I tried to compile the sqlsrv.so locally and got this same error

alexryall commented 1 year ago

Appears to be a new issue caused by something being upgraded in the last couple of days. Hopefully it gets reverted as the fix in #1436 breaks the script for ARM processors (the bug hasn't affected ARM). If this change is here to stay it will require different install scripts for ARM and AMD for myself and many others.

edit The below works for both CPU architectures and means if they fix the issue it'll go back to using unixodbc-dev like before.

ACCEPT_EULA=Y apt-get install -y msodbcsql18 mssql-tools18 unixodbc-dev && \
pecl install sqlsrv pdo_sqlsrv || \
apt-get install -y --allow-downgrades odbcinst=2.3.7 odbcinst1debian2=2.3.7 unixodbc=2.3.7 unixodbc-dev=2.3.7 && \
pecl install sqlsrv pdo_sqlsrv
delboy1978uk commented 1 year ago

I used the fix here https://github.com/microsoft/msphpsql/issues/1436#issuecomment-1428075290

bjverde commented 1 year ago

@alexryall

Thanks for the allow-downgrades tip!!

Built Docker image for Debian 11 with PHP 8.1 and 8.2 with pdo_sqlsrv-5.11.0. Below my two cent contribution, the Dockerfile links. Please note, I have not tested the connection to the database.

https://github.com/bjverde/formDocker/blob/master/debian11_php8.1_mssql/debian11_apache_php81_mssql.Dockerfile

https://github.com/bjverde/formDocker/blob/master/debian11_php8.2_mssql/debian11_apache_php81_mssql.Dockerfile

shaqaruden commented 1 year ago

Can't believe this still hasn't been fixed yet months later

absci commented 1 year ago

Can't believe this still hasn't been fixed yet months later

I tested with php:8.1-apache today and can't reproduce the error. What's the error message you get?

reinierpost commented 1 year ago

I'm having the same issue today on Ubuntu 22.04 (with PHP 8.1).

kunwarj commented 1 year ago

Following code did install the pdo_server in ubuntu 22.04 for me

https://github.com/bjverde/formDocker/blob/master/debian11_php8.2_mssql/debian11_apache_php81_mssql.Dockerfile

ENV ACCEPT_EULA=Y

RUN curl -s https://packages.microsoft.com/keys/microsoft.asc | tee /etc/apt/trusted.gpg.d/microsoft.asc | apt-key add - \
    && curl -s https://packages.microsoft.com/config/ubuntu/22.04/prod.list | tee /etc/apt/sources.list.d/mssql-release.list > /etc/apt/sources.list.d/mssql-release.list

RUN apt-get update

# install MS ODBC 18
# https://docs.microsoft.com/pt-br/sql/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server?view=sql-server-2017#debian18
RUN apt-get -y install msodbcsql18 mssql-tools18

RUN echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile
RUN echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
RUN exec bash

# https://github.com/microsoft/msphpsql/issues/1438#issuecomment-1444773949
RUN apt-get install -y --allow-downgrades odbcinst=2.3.7 odbcinst1debian2=2.3.7 unixodbc=2.3.7 unixodbc-dev=2.3.7

#RUN apt-get -y install unixodbc unixodbc-dev
RUN apt-get -y install gcc g++ make autoconf libc-dev pkg-config

##------------ Install Drive 5.10.1 for SQL Server -----------
# List version drive PDO https://pecl.php.net/package/pdo_sqlsrv
# Install Drive: https://docs.microsoft.com/pt-br/sql/connect/php/installation-tutorial-linux-mac?view=sql-server-2017
RUN apt-get install php-pear

RUN pecl install sqlsrv-5.11.0 && echo "extension=sqlsrv.so" > /etc/php/8.2/mods-available/sqlsrv.ini && \
    pecl install pdo_sqlsrv-5.11.0 && echo "extension=pdo_sqlsrv.so" > /etc/php/8.2/mods-available/pdo_sqlsrv.ini && \
    phpenmod sqlsrv pdo_sqlsrv