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

17,590

Solution 1

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

Solution 2

I was able to install/configure everything correctly. I changed the "host" to 127.0.0.1, not sure why that made a difference but it did :)

Share:
17,590
antjanus
Author by

antjanus

I am a developer and an innovator. I love to learn and I love to overcome challenges. Because of this, I tend to shift between specific roles in a given industry. My goal is to develop, design, market, and publish any kind of a website, application, program, or anything else of that kind that I can imagine and put my mind to.

Updated on June 07, 2022

Comments

  • antjanus
    antjanus almost 2 years

    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?