PHP/Apache running on Linux won’t connect to a PostgreSQL server

SELinux will block PHP/Apache from connecting to PostgreSQL (and probably any other DB) by default on some Linux distributions. If you are trying to get PHP to connect to a PostreSQL DB on a linux box for the first time and you are sure your pg_hba.conf on the target box is setup correctly then try this:

setsebool -P httpd_can_network_connect 1

This should configure SELinux to allow Apache/PHP to connect to other hosts.

3 Comments

Add Yours →

Is a restart required to put this rule into place? If not, does this hold through a restart?

Good useful tip!

You can connect to the 32-bit postgresql server from 64-bit programs on the computer the server is running on or other computers if a 64-bit libpq or psqlODBC driver is installed where the program is running.

Leave a Reply