Php: Can't install pdo_psql with docker-php-ext-install

Created on 13 Apr 2016  路  15Comments  路  Source: docker-library/php

I was trying to install pdo_psql on fpm-alpine flavour like:

docker-php-ext-install pdo pdo_pgsql

I was getting first the following error:

configure: error: Cannot find libpq-fe.h. Please specify correct PostgreSQL installation path

So I decide to install libpq:

RUN echo "@edge http://nl.alpinelinux.org/alpine/edge/main" >> /etc/apk/repositories
RUN apk --no-cache add \
    libpq@edge

Same error after that and then I try installing postgresql like:

RUN echo "@edge http://nl.alpinelinux.org/alpine/edge/main" >> /etc/apk/repositories
RUN apk --no-cache add \
    postgresql \
    libpq@edge

And then getting different error:

configure: error: Unable to build the PDO PostgreSQL driver: a newer libpq is required

That's why I'm trying with the edge version of libpq but...

And I'm get stuck in this step not sure what could be wrong but I can't install pdo_pgsql

btw my infrastructure it's have one container per thing, so I have a container for nginx and a container for php-fpm and another container with postgres so my goal it's have everything split between containers

Most helpful comment

The same issue but on php:5.6-fpm, not alpine.

FROM php:5.6-fpm

RUN docker-php-ext-configure pgsql -with-pgsql=/usr/local/pgsql \
    && docker-php-ext-install pgsql pdo_pgsql

configure: error: Cannot find libpq-fe.h. Please specify correct PostgreSQL installation path


The solution as above is:

FROM php:5.6-fpm

RUN apt-get update

# Install Postgre PDO
RUN apt-get install -y libpq-dev \
    && docker-php-ext-configure pgsql -with-pgsql=/usr/local/pgsql \
    && docker-php-ext-install pdo pdo_pgsql pgsql

All 15 comments

Could this issue be related with the C libraries on Alpine? I have notice you are using g++ and gcc

Ok! fix my issue! :)

It's kind of related with this https://bugs.alpinelinux.org/issues/3642 and this https://bugs.alpinelinux.org/issues/4109

And what I did to fix it was install first postgresql-dev like so:

FROM php:fpm-alpine

RUN set -ex \
  && apk --no-cache add \
    postgresql-dev

RUN docker-php-ext-install pdo pdo_pgsql

And that works! :) the links suggest that we should have a small package to satisfy that dependency and be able to install the pdo_psql

The same issue but on php:5.6-fpm, not alpine.

FROM php:5.6-fpm

RUN docker-php-ext-configure pgsql -with-pgsql=/usr/local/pgsql \
    && docker-php-ext-install pgsql pdo_pgsql

configure: error: Cannot find libpq-fe.h. Please specify correct PostgreSQL installation path


The solution as above is:

FROM php:5.6-fpm

RUN apt-get update

# Install Postgre PDO
RUN apt-get install -y libpq-dev \
    && docker-php-ext-configure pgsql -with-pgsql=/usr/local/pgsql \
    && docker-php-ext-install pdo pdo_pgsql pgsql

@Aliance This also fixes the issue for php:apache 馃憤

I am facing the same issue, but when I follow zot24 advice... the pdo is installed and seems to work BUT
when I then run psql in the shell I get

Error relocating /usr/bin/psql: PQresultVerboseErrorMessage: symbol not found
Error relocating /usr/bin/psql: PQsetErrorContextVisibility: symbol not found
Error relocating /usr/bin/psql: PQencryptPasswordConn: symbol not found

Any suggestions

Basically when I add postgresql-dev to my current installation pf postgresql (10.1) then I no longer can use psql command... drives me nuts

I now solved it like this:

#... install postgres pdo
set -ex \
  && apk --no-cache add \
    postgresql-dev

docker-php-ext-install pdo pdo_pgsql
apk del postgresql-dev
apk add --upgrade postgresql --update-cache --repository http://dl-3.alpinelinux.org/alpine/edge/main/

I got stuck on the same problem and your comments did help me to get it running, but you do not need to install the complete postgres package, postgres-libs is sufficient (pdo is already installed, but I needed to install the pgsql extension):

RUN set -ex \
    && apk --no-cache add postgresql-libs postgresql-dev \
    && docker-php-ext-install pgsql pdo_pgsql \
    && apk del postgresql-dev

apt-get install libpq-dev

Thanks @acodercat ,
your solution is still "doing the trick" if you are using the docker container "php:7.1-cli".

apt-get install libpq-dev
&& docker-php-ext-install pdo_pgsql

You probably need to run "apt-get update" first. 馃槈

The same issue but on php:5.6-fpm, not alpine.

FROM php:5.6-fpm

RUN docker-php-ext-configure pgsql -with-pgsql=/usr/local/pgsql \
    && docker-php-ext-install pgsql pdo_pgsql

configure: error: Cannot find libpq-fe.h. Please specify correct PostgreSQL installation path

The solution as above is:

FROM php:5.6-fpm

RUN apt-get update

# Install Postgre PDO
RUN apt-get install -y libpq-dev \
    && docker-php-ext-configure pgsql -with-pgsql=/usr/local/pgsql \
    && docker-php-ext-install pdo pdo_pgsql pgsql

Thank you so much, mate.

If somebody stumbles upon this and you're using one of the debian based images:

FROM php:apache

RUN apt-get update; \
    apt-get install -y libpq5 libpq-dev; \
    docker-php-ext-install pdo pdo_pgsql; \
    apt-get autoremove --purge -y libpq-dev; \
    apt-get clean ; \
    rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/*

Note: you must leave libpq5 for the psql extension to function. Its dev headers though are only needed for compiling the php extension and can and should be removed.

My addition of pdo_pgsql for urbit/lumen-php-fpm:

FROM urbit/lumen-php-fpm

RUN apk --no-cache --update --repository http://dl-
cdn.alpinelinux.org/alpine/v$ALPINE_VERSION/main/ add \
    postgresql-dev

RUN docker-php-ext-install pdo_pgsql
RUN apt-get install -y libpq-dev \
    && docker-php-ext-configure pgsql -with-pgsql=/usr/local/pgsql \
    && docker-php-ext-install pdo pdo_pgsql pgsql
Was this page helpful?
0 / 5 - 0 ratings