简体   繁体   English

使用pg_connect在php-fpm / CentOS6上返回false

[英]Using pg_connect returning false on php-fpm / CentOS6

I'm now developing a site on CentOS/nginx/postgresql/php(php-fpm). 我现在正在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 当我在访问http://example.com/dbcon.php上运行该代码时,它只会返回false

I haven't seen any error or warning displayed. 我没有看到显示任何错误或警告。

Direct php script executing: SUCCESS 直接执行PHP脚本:成功

But if i call: 但是如果我打电话:

php < dbcon.php

It was returning: 它正在返回:

resource(5) of type (pgsql link) 类型的resource(5)(pgsql链接)

Using httpd: FAIL 使用httpd:失败

I changed the http server from nginx to httpd, the problem still exists. 我将http服务器从nginx更改为httpd,问题仍然存在。

Using spawn-fcgi: SUCCESS 使用spawn-fcgi:成功

And then I stop the php-fpm service, and run a spawn-fcgi instead, there was no problem. 然后我停止php-fpm服务,而是运行spawn-fcgi,没有问题。


Question: 题:

What's the matter with php-fpm? php-fpm有什么问题? How can I configure the php-fpm and work around the problem? 如何配置php-fpm并解决此问题?

That was because of a selinux setting. 那是因为selinux的设置。

Worked around by: 解决方法:

setsebool -P httpd_can_network_connect_db 1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM