How to install pdo_odbc in Docker php image


I'm trying to connect to mssql with PDO and Laravel but I think I'm having issues installing the driver. There are no build errors, but I've looked around everywhere to try to find a solution, and they produce either an error or just does not work. When attempting to make a connection to a mssql server, it gives this error:

Illuminate\Database\QueryException: could not find driver (SQL: SELECT * FROM SAMPLE_VIEW_SM1 WHERE STUDENTS_ID=1) in file /var/www/vendor/laravel/framework/src/Illuminate/Database/Connection.php on line 664

Caused by
PDOException: could not find driver in file /var/www/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php on line 70

Here is my dockerfile:

FROM php:7.3-fpm-buster

ENV DEBIAN_FRONTEND=noninteractive

RUN rm /etc/apt/preferences.d/no-debian-php

RUN apt-get update -y && apt-get install -y \
    openssl \
    zip \
    unzip \
    git \
    curl \
    freetds-common \
    freetds-bin \
    unixodbc \
    unixodbc-dev \
    php-smbclient \

RUN docker-php-ext-configure pdo_odbc --with-pdo-odbc=unixodbc,/usr
RUN docker-php-ext-install pdo_odbc
RUN docker-php-ext-enable pdo_odbc
# Install node and dependencies

RUN curl -sL | bash -
RUN apt-get install -y nodejs

RUN mkdir /cache
WORKDIR /cache

COPY package.json ./
COPY package-lock.json ./
RUN npm install

# Set file size limits

RUN echo "post_max_size=50M" >> /usr/local/etc/php/php.ini-production
RUN echo "upload_max_filesize=10M" >> /usr/local/etc/php/php.ini-production
RUN echo "memory_limit=6400M" >> /usr/local/etc/php/php.ini-production

RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"

# Create application's working directory
WORKDIR /var/www
COPY . .

RUN curl -sS | php -- --install-dir=/usr/local/bin --filename=composer

RUN composer install

RUN cp -r ./vendor/. /cache/vendor/

RUN chmod -R a+rwX /var/www/storage

RUN chmod -R +x ./





I just published a solution related to this, I hope it serves you, greetings.

People are also looking for solutions to the problem: regex - Convert String to Object PHP


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.