3

I have a CentOS apache web server that I've set up to access our database server (also CentOS). There is an entry for the web server in pg_hba.conf on the database server. I can connect without issue on the command line (using "php -a" under bash) of the machine running the webserver. Here is my script (with credentials mangled)

if(pg_connect("host=192.168.6.11 port=5432 dbname=C_test user=Cuser password=c1811wet"))  { 
    echo 'connected'; 
} else { 
    echo 'not';
}

When run this script from the command line, I get 'connected'. When I run as a web page (http://some.host.name/test.php) - 'not'.

Ideas? My searches all lead me to either the listen='*' setting in postgresql.conf or adding the web server ip to pg_hba.conf - but both of these are in place.

Update:

@Jorge - the webserver and the db server are on different IPs.

@Nicarus The line added to pg_hba.conf was:

host    C_test        Cuser 192.168.100.166     255.255.255.255 md5

I am pretty sure that is working to allow access from this IP - as noted, if I run the script on the command line it connects, just not running from a web page.

@lwb - Thanks for the suggestion - I tried adding the suggested line to pg_hba.conf, and restarting the postgresql service. Service comes up cleanly but no change in behavior - I can connect on the command line but not from the web page.

@Massimiliano - it appears that I'm using the same /etc/php.ini, and parsing the same series of additional ini files (except apc.ini, which is ignored on command line) on both command line and webserver. I just used phpinfo() to display the Loaded Configuration File and ran it in both environments.

T Carey
  • 57
  • 6

1 Answers1

2

I reached a resolution on this issue.

  • First, I went to my dbserver and ran tail -f on the postgresql log. This revealed that the request from the web page was not even reaching the dbserver, while the same script run from command line, connected.

  • another helpful post on StackOverflow revealed the solution - it's an SELinux problem, fixed by the following:

    sudo setsebool -P httpd_can_network_connect_db on

Community
  • 1
  • 1
T Carey
  • 57
  • 6