Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot connect to PgSQL via Laravel SQLSTATE[08006] [7] FATAL

I'm trying to connect to pgsql via laravel and finally got everything setup (pgsql server running, pdo installed, all libs installed). I'm running on a VPS (CentOS) managed via CPanel/WHM.

Here's what I'm doing: I'm trying to create a user database via artisan (Laravel's command line) using migrate:install.

For those that don't use Laravel, artisan uses php's PDO for pgsql to connect. Here are my settings:

    'pgsql' => array(
        'driver'   => 'pgsql',
        'host'     => 'localhost',
        'database' => 'dbname',
        'username' => 'username',
        'password' => 'password',
        'charset'  => 'utf8',
        'prefix'   => '',
    ),

I've also setup a test.php file:

$dbconn = pg_connect("host=localhost port=5432 dbname=dbname user=username password=password");

which also fails. I used phpPgAdmin to see what's up and all of the permissions are set correctly, the database shows up, the username is correct, same with password. I checked where postgre (version 8.4.12 btw) was running and phpPgAdmin tells me "localhost:5432".

The error I get via the command line is the following:

SQLSTATE[08006] [7] FATAL: no pg_hba.conf entry for host "::1", user "myusername", database "my_database", SSL OFF

Now, I tried to find the pg_hba.conf file but I'm not entirely sure where to look for it. Same goes for the error/access logs for pg and google hasn't been any help as far as this goes.

Any idea on what I can do?

like image 275
antjanus Avatar asked Oct 07 '22 22:10

antjanus


1 Answers

localhost points to IPV6 ::1 address on your system. Postgresql makes the difference between ipv6 and ipv4 addresses when dealing with access list.

like image 194
greg Avatar answered Oct 11 '22 18:10

greg