我在 OSX 上的 VirtualBox 中运行 CentOS 7.Apache、PHP 5.4 和 PostgreSQL 9.2 都在运行.但是,当我的(简单)php 脚本尝试连接到 PostgreSQL 时,它不起作用:
I have CentOS 7 running in VirtualBox on OSX. Apache, PHP 5.4 and PostgreSQL 9.2 are all running. But, when my (simple) php-script tries to connect to PostgreSQL it doesn't work:
警告:pg_connect():无法连接到 PostgreSQL 服务器:可以未连接到服务器:权限被拒绝服务器是否在主机上运行127.0.0.1"并接受端口 5432 上的 TCP/IP 连接?在/var/www/html/pg.php 在第 7 行
Warning: pg_connect(): Unable to connect to PostgreSQL server: could not connect to server: Permission denied Is the server running on host "127.0.0.1" and accepting TCP/IP connections on port 5432? in /var/www/html/pg.php on line 7
检查:
托管所有所有 0.0.0.0/0 信任
host all all 0.0.0.0/0 trust
但是php连接不上....这是我的脚本:
But php can't connect.... This is my script:
<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
echo 'hello world!';
$conn = pg_connect('host=127.0.0.1 port=5432 user=postgres dbname=postgres');
?>
内部连接工作(psql),外部连接也工作(我的笔记本电脑上的pgAdmin),但是php连接不起作用......
Internal connections work (psql), external connections also work (pgAdmin on a my laptop), but the php connection doesn't work...
出了什么问题?我错过了什么?
What is going wrong? What is it that I'm missing?
可能 SELinux 阻塞了你的数据库连接.
Probably SELinux is blocking your database connection.
确保您设置了正确的布尔值以允许您的 Web 应用程序与数据库通信:
Make sure that you set the correct boolean to allow your web application to talk to the database:
sudo setsebool -P httpd_can_network_connect_db 1
这篇关于PHP 无法在 CentOS 7 上连接到 PostgreSQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!