After migration to a new VPS and trying website on new server(Centos 7), Selinux somehow prevents http from accessing Postgresql:
pg_connect(): Unable to connect to PostgreSQL server: could not connect to server: Permission denied Is the server running on host "127.0.0.1" and accepting TCP/IP connections on port 6432
and yes my postgresql in on port 6432 because of pgbouncer that we use to reduce server load. I googled around and find out it's because of Selinux so I used selinux commands to allow httpd connection to db setsebool -P httpd_can_network_connect_db on
and it works as in when I look in Selinux config with sestatus -b
it's turned ON
but the problem still exists...
pg_connect(): Unable to connect to PostgreSQL server: could not connect to server: Permission denied Is the server running on host "127.0.0.1" and accepting TCP/IP connections on port 6432
Funny thing is I know it's because of Selinux cause when I use setenforce 0
It works and connect to postgresql without any problem.
what should I do?
semanage port -a -t postgressql_port_t -p tcp 6432
ValueError: Type postgressql_port_t is invalid, must be a port type
unreserved_port_t
, sorry last time I touched selinux was loong time ago.postgressql_port_t
typo it should bepostgresql_port_t
and I tested it. It works. Thanks