Using pg_connect returning false on php-fpm / CentOS6

I'm now developing a site on CentOS/nginx/postgresql/php(php-fpm).

The problem:

And I have such a database connection code which blocks:

$dbcon = pg_connect(
    "host=localhost port=5432 dbname=shex_utf8 user=webmaster password=webmaster"
);
var_dump($dbcon);

It only return false when I run that code on visiting http://example.com/dbcon.php

I haven't seen any error or warning displayed.

Direct php script executing: SUCCESS

But if i call:

php < dbcon.php

It was returning:

resource(5) of type (pgsql link)

Using httpd: FAIL

I changed the http server from nginx to httpd, the problem still exists.

Using spawn-fcgi: SUCCESS

And then I stop the php-fpm service, and run a spawn-fcgi instead, there was no problem.


Question:

What's the matter with php-fpm? How can I configure the php-fpm and work around the problem?

Answers


That was because of a selinux setting.

Worked around by:

setsebool -P httpd_can_network_connect_db 1

Need Your Help

Google XPATH importxml can find "show" but not "showcount" or "count"

xpath google-sheets

Using this webpage as an example http://forums.macrumors.com/showthread.php?t=1688317

What are the benefits of Mercurial or git over svn for branching/merging?

svn git mercurial merge

I've heard for instance that merging branches with git or mercurial is easier than with svn.