apstyx's avatar

Homestead - L4.2 - PGSQL - PDOException - could not find driver

Hi all, hopefully somebody can help.

I have a new installation of homestead with a laravel 4.2 application making use of postgresql.

The error in the log file when trying to interact with the db is: local.ERROR: exception 'PDOException' with message 'could not find driver' in :

I have tested the following:

  1. According to a phpinfo(); page php is configured with pdo + pdo_pgsql
  2. Verified no 1 with the following code:
<?php

foreach (PDO::getAvailableDrivers() as $driver)
    {
        echo $driver . '<br />';
    }

$dbh = new PDO ('pgsql:host=xxxx;dbname=xxxx', 'xxxx', 'xxxx')
or die ("Error");

try {
    $dbh = new PDO('pgsql:host=xxxx;dbname=xxxx', 'xxxx', 'xxxx');
    foreach($dbh->query('SELECT * from users') as $row) {
        print_r($row);
    }
    $dbh = null;
} catch (PDOException $e) {
    print "Error!: " . $e->getMessage() . "<br/>";
    die();
}

which produced the following output:

mysql
pgsql
sqlite
Array ( [id] => 1 .........................................
  1. I can run php artisan migrate and php artisan tinker and create the db tables and create db entries.

Thus I have determined the following:

  1. PHP is running and configured correctly via both web and cli
  2. Postgresql is running and accessible via artisan
  3. I don't know why the laravel web interaction with pgsql is not working

I am at my wits end and would appreciate any help.

0 likes
4 replies
apstyx's avatar
apstyx
OP
Best Answer
Level 1

When in doubt update everything:

sudo apt-get update && sudo apt-get upgrade

After wasting time on nginx configuration, php5-fpm configuration and obviously php ini configuration a simple update and upgrade fixed all my problems.

gpopoteur's avatar

I'm facing exactly the same Issue, I can access Postgresql via Artisan but when I try to access the Database via a web request to Laravel I get the following error ERROR: exception 'PDOException' with message 'could not find driver'.

I'm using Laravel 5 and Homestead 2.

I did what @apstyx suggested but it is still not working :-/

gooshan's avatar

Similar thing here. I am running laravel 5 and homestead. There was PDO driver problem that was driving me mad. It turns out the problem lies with HHVM. HHVM and the pgsql pdo driver simply dont work together at this point.

1 like
safarideny's avatar

@gooshan,

I spent a week trying to find out what happened.

Just to find out in one lazy night I tried HHVM.

Arghh.

Thanks by the way.

Cheers.

Please or to participate in this conversation.