Fabien Snauwaert Fabien Snauwaert - 1 year ago 80
PHP Question

Heroku local: how to install support for Postgres

I am using

heroku local
to try and develop in PHP locally before pushing to heroku.

However, I am not able to use Postgres locally because the PDO driver is missing:

  • Getting a
    'PDOException' with message 'could not find driver'
    error message

  • And, indeed,
    reveals that
    is not installed.

How can I install (or enable?) PostgreSQL PDO (pdo_pgsql) on
heroku local

I could not find anything in the official docs, nor online. (The docs seem to be lacking for PHP and, especially, on how to use heroku locally.)

FYI, running Mac OS X.

If needed, here's the minimal example I'm working with for testing purposes:

* postgres-helloworld.php
* Runs fine on XAMPP, which has PHP Version 5.5.15 with pdo_pgsql installed.
* But won't run on heroku local, which has PHP Version 5.5.34 WITHOUT pdo_pgsql installed.
* `PDOException`, `could not find driver'`
$dbh = new PDO( "pgsql:dbname=test;host=localhost", 'fabien', NULL );
$res = $dbh->query( 'SELECT name FROM test_table' )->fetchAll( PDO::FETCH_ASSOC );
echo $res[0]['name']; // echoes the content of said table, i.e. `hello database` -- OK



I realized my whole model of what
heroku local
does was totally off. It merely does this:

“Heroku Local reads configuration variables from a .env file.” (from https://devcenter.heroku.com/articles/heroku-local)

I'd wrongly assumed it provided, locally, the same sort of flexibility heroku provides in the cloud (i.e.: dev-prod-parity, e.g.: the ability to pick which PHP version to run and reproduce locally the same setup as in the cloud), and that it came with its own binaries.

In reality,
heroku local
merely relies on the system's default PHP install and extensions (or lack thereof) for running the web server.

Once understood, the problem became to fix it by installing pdo_pgsql on the local system, as per Shyam Bhimani's solution.


Try this:

$ ./configure --with-pdo-pgsql

Use --with-pdo-pgsql[=DIR] to install PDO PostgerSQL extension, where the optional [=DIR] is the PostgreSQL base install directory, or the path to pg_config.

for more detail you can follow this two documents (1) (2)