无法使用PHP pg_connect()连接到PostgreSQL

时间:2010-08-14 02:12:14

标签: php postgresql centos

编辑:我刚刚意识到这个问题可能更适合ServerFault。主持人请将其移动,而不是复制它?感谢。

我已经检查过php-info,并且Postgresql扩展已经存在(pg_connect()未定义)。我也可以在localhost上使用psql连接到postgresql(我已经适当地编辑了我的pg_hba.conf文件)。这是不起作用的代码:

<?php
$dbconn = pg_connect("host=localhost port=5432 dbname=mydb user=myuser password=mypass") or die('Could not connect: ' . pg_last_error());
?>

此代码只会导致浏览器中显示“无法连接:”。

我检查了我的apache日志,这是相关的错误消息:

PHP Warning:  pg_connect() [<a href='function.pg-connect'>function.pg-connect</a>]: 
Unable to connect to PostgreSQL server: could not connect to server: Permission 
denied\n\tIs the server running on host &quot;localhost&quot; and accepting\n\tTCP/IP 
connections on port 5432?

我该如何修复/调试它?

编辑:我正在使用Centos 5.4 btw。

1 个答案:

答案 0 :(得分:10)

  

无法连接到服务器:权限被拒绝

     

编辑:我正在使用Centos 5.4 btw。

检查/var/log/audit/audit.log。有可能你正在达到SELinux规则。

相关问题