centos中apache连接postgresql提示SQLSTATE[08006] [7] could not connect to server: Permission denied

centos中apache连接postgresql提示:

PDO Connection Error: SQLSTATE[08006] [7] could not connect to server: Permission denied
Is the server running on host "127.0.0.1" and accepting
TCP/IP connections on port 5432?


This happen because SELinux status is enabled and didn’t enabled the specific permission to allow Apache to use HTTP connections

?
1
2
3
4
5
6
# /usr/sbin/sestatus | grep SELinux
SELinux status:                 enabled
SELinuxfs mount :                /selinux
 
#  /usr/sbin/sestatus | grep mode
Current mode:                   enforcing

 

The Solution:

If you don’t want to use SELinux then disabling it, it’s an option.
But if you prefer to use SELinux for the other protections that it offers then, better enable the specific permission to allow Apache to issue HTTP connections. To do this run as root:

?
1
setsebool -P httpd_can_network_connect 1

More about SELinux Booleans read on Tips And Tricks Centos Wiki

关闭SELinux
#vi /etc/selinux/config
将文件中的SELINUX="" 为 disabled ,然后重启。
如果不想重启系统,使用命令setenforce 0注:setenforce 1 设置SELinux 成为enforcing模式
setenforce 0 设置SELinux 成为permissive模式
然后重启postgres:

/etc/init.d/postgresql-9.3 restart

你可能感兴趣的:(centos中apache连接postgresql提示SQLSTATE[08006] [7] could not connect to server: Permission denied)