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

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

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 25
  • Comments: 15 (1 by maintainers)

Commits related to this issue

Most upvoted comments

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

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

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

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.

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

apt-get install libpq-dev

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/

You probably need to run “apt-get update” first. 😉

@Aliance This also fixes the issue for php:apache 👍

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