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
이제 호스트 컴퓨터 (ip : 192.168.0.117)에서 클라이언트 pgAdmin3 (사용자 : postgres, 암호 : postgres)을 사용하여 Postgres에 연결할 때 그렇게 할 수 있으며 모든 것이 잘 작동하지만 CentOS VM에서 실행되는 PHP는 할 수 없습니다. 데이터베이스에 연결 :
$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?
누구에게 제안이 있습니까?
SELinux가 연결을 차단할 가능성이 있습니다. 연결이 차단되었을 때 / var / log / messages에서 로그 항목을 찾을 수 있어야합니다.
SELinux에서이 플래그를 설정해보십시오.
setsebool -P httpd_can_network_connect_db on
RedHat에는이 SELinux 플래그에 대한 몇 가지 문서가 있습니다. 1
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다