无法通过 Laravel SQLSTATE[08006] [7] 连接到 PgSQL
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11972121/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Cannot connect to PgSQL via Laravel SQLSTATE[08006] [7] FATAL
提问by antjanus
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.
我正在尝试通过 laravel 连接到 pgsql 并最终完成了所有设置(pgsql 服务器正在运行,pdo 已安装,所有库已安装)。我在通过 CPanel/WHM 管理的 VPS (CentOS) 上运行。
Here's what I'm doing: I'm trying to create a user database via artisan (Laravel's command line) using migrate:install.
这是我正在做的事情:我正在尝试使用 migrate:install 通过 artisan(Laravel 的命令行)创建用户数据库。
For those that don't use Laravel, artisan uses php's PDO for pgsql to connect. Here are my settings:
对于那些不使用 Laravel 的人,artisan 使用 php 的 PDO for pgsql 进行连接。这是我的设置:
'pgsql' => array(
'driver' => 'pgsql',
'host' => 'localhost',
'database' => 'dbname',
'username' => 'username',
'password' => 'password',
'charset' => 'utf8',
'prefix' => '',
),
I've also setup a test.php file:
我还设置了一个 test.php 文件:
$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".
这也失败了。我使用 phpPgAdmin 来查看发生了什么并且所有权限都设置正确,数据库显示出来,用户名正确,密码相同。我检查了 postgre(顺便说一句 8.4.12 版)在哪里运行,phpPgAdmin 告诉我“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.
现在,我试图找到 pg_hba.conf 文件,但我不完全确定在哪里寻找它。pg 的错误/访问日志也是如此,就这一点而言,google 没有任何帮助。
Any idea on what I can do?
知道我能做什么吗?
采纳答案by greg
localhost points to IPV6 ::1 address on your system. Postgresql makes the difference between ipv6 and ipv4 addresses when dealing with access list.
localhost 指向您系统上的 IPV6 ::1 地址。Postgresql 在处理访问列表时会区分 ipv6 和 ipv4 地址。
回答by antjanus
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 :)
我能够正确安装/配置一切。我将“主机”更改为 127.0.0.1,不知道为什么会有所不同,但确实如此:)

