<分区>
我有一台运行在 VirtualBox 上的 CentOS 6.5 虚拟机。 我在上面设置了 Apache、PHP、PHP Postgres 扩展 (php-pgsql) 和 Postgres 数据库。 我修改了 pg_hba.conf 文件以允许连接:
# "local" is for Unix domain socket connections only
local all all peer
# IPv4 local connections:
host all all 127.0.0.1/32 ident
# IPv6 local connections:
host all all ::1/128 ident
host all all 192.168.0.0/24 trust
host all all 0.0.0.0/0 md5
这是我的 iptables 文件:
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:8090
ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:postgres
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
现在,当我使用客户端 pgAdmin3(用户:postgres,密码:postgres)从我的主机(ip:192.168.0.117)连接到 Postgres 时,我能够做到这一点并且一切正常但 PHP 在我的 CentOS 上运行虚拟机无法连接到数据库:
$connection_string = "host=localhost port=5432 dbname=rt_prezzario user=postgres password=postgres";
$resource = pg_connect($connection_string);
这是当我运行这两行代码时 PHP 触发的警告:
Warning: pg_connect(): Unable to connect to PostgreSQL server: could not connect to server: Permission denied Is the server running on host "localhost" (::1) and accepting TCP/IP connections on port 5432?
有人有建议吗?