W
W
WenSiL2018-05-06 11:26:10
PHP
WenSiL, 2018-05-06 11:26:10

How to add PostgreSQL driver to php-fpm docker container?

There is this Dockerfile:

FROM php:fpm

RUN apt-get update && apt-get install -y \
        curl \
        wget \
        git \
        libfreetype6-dev \
        libjpeg62-turbo-dev \
        libmcrypt-dev \
        libpng-dev \
    && pecl install mcrypt-1.0.1 \
    && docker-php-ext-enable mcrypt \
    && docker-php-ext-install -j$(nproc) iconv mbstring mysqli pdo_mysql zip \
    && docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
    && docker-php-ext-install -j$(nproc) gd

    RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

    ADD ./php.ini /usr/local/etc/php/conf.d/40-custom.ini

    WORKDIR /var/www

    CMD ["php-fpm"]

Can you tell me what needs to be changed in the dockerfile to make php work with postgres? I don't understand at all how to work with php extension in docker. I tried just changing mysqli to pgsql and pdo_mysql to pdo_pgsql, but it didn't help. And how do you generally connect from php to a database that is also in a container? As usual, through localhost? Or are there any specifics? And the last question. I read that mcrypt has been deprecated, how do I replace it in the dockerfile with something up-to-date?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
ivankomolin, 2019-01-08
@ivankomolin

RUN apt-get update && \
    apt-get install -y libpq-dev && \
    docker-php-ext-install pdo pdo_pgsql pgsql

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question