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.

Comments

3 responses to “PHP/Apache running on Linux won’t connect to a PostgreSQL server”

  1. Matt Mendick Avatar
    Matt Mendick

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

    Good useful tip!

  2. mfoster Avatar

    I restarted Apache but not the machine and that seemed to work.

  3. Hans Shelton Avatar

    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