56

I am trying to enable the pdo driver for my php installation, but when I runn the command

./configure --prefix=/usr/local/webserver/php --with-apxs2=/usr/local/webserver/apache2/bin/apxs --enable-mbstring --enable-intl --with-icu-dir=/usr --with-pgsql=/usr/local/webserver/postgres --with-pdo-pgsql=/usr/local/webserver/postgres

I get

"Unable to build the PDO PostgreSQL driver: libpq 7.4+ is required"

I install postgresql in that directory

/usr/local/webserver/postgres

I installed postgresql 9.0.4.1 using the bin package and using php 5.3

Richard Pérez
  • 1,467
  • 3
  • 15
  • 18

5 Answers5

113

Pecl PDO package is now deprecated. By the way the debian package php5-pgsql now includes both the regular and the PDO driver, so just:

apt-get install php-pgsql

Apache also needs to be restarted before sites can use it:

sudo systemctl restart apache2
danlynn
  • 143
  • 1
  • 5
Alex
  • 1,364
  • 1
  • 9
  • 10
  • I wasn't sure if that package included the PDO driver. Thanks! – btleffler Mar 28 '15 at 13:25
  • 9
    Remember to execute: `php5enmod pgsql` after that – Thiago Mata Nov 13 '15 at 02:23
  • After that, it is also needed to restart your web server – Junior Mayhé Nov 27 '15 at 14:21
  • I don't remember how I solved by that moment, but what I can say now, is that for both Debian and Ubuntu what @alex say, is the correct way to install it. However I must said that versions of Ubuntu like 14 and maybe before of it, already include a version of Postgres (I think 9.0) if you want to install a new one like 9.3 you can use apt-get purge postgresql -y && apt-get install postgresql-9.3 -y – Richard Pérez Mar 02 '16 at 20:09
28

Try the packaged pecl version instead (the advantage of the packaged installs is that they're easier to upgrade):

apt-get install php5-dev
pecl install pdo
pecl install pdo_pgsql

or, if you just need a driver for PHP, but that it doesn't have to be the PDO one:

apt-get install php5-pgsql

Otherwise, that message most likely means you need to install a more recent libpq package. You can check which version you have by running:

dpkg -s libpq-dev
Dave Jarvis
  • 30,436
  • 41
  • 178
  • 315
wildpeaks
  • 7,273
  • 2
  • 30
  • 35
24

If you're using the wonderful ondrej/php ubuntu repository with php7.0:

sudo apt-get install php7.0-pgsql

For ondrej/php Ubuntu repository with php7.1:

sudo apt-get install php7.1-pgsql

Same repository, but for php5.6:

sudo apt-get install php5.6-pgsql

Concise and easy to remember. I love this repository.

Dylan Pierce
  • 4,313
  • 3
  • 35
  • 45
9

PDO driver for PostgreSQL is now included in the debian package php5-dev. The above steps using Pecl no longer works.

Will
  • 1,989
  • 20
  • 19
3

If you are using PHP 5.6, the command is:

sudo apt-get install php5.6-pgsql
joan16v
  • 5,055
  • 4
  • 49
  • 49
  • This was it for me -- spent several hours banging my head against the wall with: " [PDOException] could not find driver" in Laravel Homestead – Ben Wilson Jun 19 '17 at 08:32