How to enable PostgreSQL driver for PDO for php 7?

I have a ubuntu 14.4 server with apache2 and php 7.1.6.

I also have PostgreSQL 9.3 installed on it. I now need to connect to this data from php code, using PDO.

I have tried the following:

  1. Install Pgsql driver with: sudo apt install php7.0-pgsql
  2. Now when I try to enable postgres PDO drivers using sudo phpenmod pdo_pgsql, I get the following error messages:

WARNING: Module pdo_pgsql ini file doesn't exist under /etc/php/7.1/mods-available

How do you correctly install & enable the PDO drivers for PostGres for php 7?


You've been running php7.1 while you installed php7.0 pgsql module.

Try php -v to check your version and install php7.1-pgsql.


Also you need to uncomment these lines:

extension=php_pdo_pgsql.dll
extension=php_pgsql.dll

in /etc/php/7.1/cli/php.ini .


In addition to what others said, try:

sudo phpenmod pdo_pgsql