postgresql connection failure:SQLSTATE[08006] [7] 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?
PHP 程序无法连接到 CentOS 上的PostgreSQL,但是在 CentOS 服务器上却能正常运行 psql,
操作如下:多次重启 PG 数据库后发现 CGI 脚本无法连接数据库,但是可以使用 psql 连接上数据库
PHP 程序报错如下:
PostgreSQL server: could not connect to server: Permission denied Is the server running on host "localhost" (127.0.0.1)
and accepting TCP/IP connections on port 5432?
网上查了很多文章,发现是SELinux(Linux上的强制访问控制安全模块)惹得祸,很想关闭它,
但是据说他是系统被攻破后的最后一道防线,那就暂时记录此类问题的解决方案,以后有时间的话,好好研究一下这个SELinux!
此问题的原因是SELinux阻止httpd进程--httpd_can_network_connect_db 连接数据库--不管是哪种类型的数据库
所以需要确保设置正确的布尔值以允许Web应用程序与数据库通信,使用setsebool命令改变该布尔变量的状态,从而使得httpd进程能够访问数据库服务器:
sudo setsebool -P httpd_can_network_connect_db
改变成功后,可以使用getsebool命令进行查看:
/usr/sbin/getsebool httpd_can_network_connect_db
查看 SELinux 设置的所有 Booleans 值
getsebool -a
上述状态改变只是暂时性的,一旦系统重启,该变量状态将改变回初始状态,因此,可以使用如下命令永久性改变状态:
/usr/sbin/setsebool -P httpd_can_network_connect_db on
如需关闭SELinux则可以执行以下操作
修改/etc/selinux/config SELINUX=enforcing 为 SELINUX=disabled
参考链接:
https://stackoverflow.com/questions/27749691/php-cant-connect-to-postgresql-on-centos-7
关于 SELinux 的参考链接:
https://wiki.centos.org/TipsAndTricks/SelinuxBooleans#line-44
http://www.blogjava.net/ycyk168/archive/2012/09/09/387340.html
postgresql connection failure:SQLSTATE[08006] [7] 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?的更多相关文章
- JDBC 连Sql Server 接数据库--The TCP/IP connection to the host localhost, port 1433 has failed
原文:https://blog.csdn.net/qq_39241986/article/details/80848855 这样的错误,你有遇到过吗? The TCP/IP connection to ...
- 已经安装了客户端,但是cmd输入sqlcmd报错:Sqlcmd:Error:Connection failure.SQL Native Client is not installed correctly
以前安装了sqlserver2008,没有卸载掉,后面又安装了sqlserver2014,所以系统环境变量中既有2008的环境变量的配置,又有2014的环境变量的配置,所以在终端输入sqlcmd时报错 ...
- ADO Connection failure
使用ado连接,频繁报错.为何?是网络的问题吗?太灵敏了.Connection failure. 跟大文本又关系??
- Linux 出现telnet: 127.0.0.1: Connection refused错误解决办法
Linux 出现telnet: connect to address 127.0.0.1: Connection refused错误解决办法 没有xinetd服务: 1./etc/init.d目录中放 ...
- ERROR [RMI TCP Connection(3)-127.0.0.1] - init datasource error
运行报错 ERROR [RMI TCP Connection(3)-127.0.0.1] - init datasource error, url: jdbc:mysql://localhost:33 ...
- Linux用sendmail发信失败,提示Connection refused by [127.0.0.1]
现象: Linux用sendmail发信失败,提示Connection refused by [127.0.0.1] 29 14:10:44 iZ257p7xxilZ sendmail[3395]: ...
- android异常: java.net.ConnectException: localhost/127.0.0.1:8080 - Connection refused
android手机做下载文件时,报了如下异常: java.net.ConnectException: localhost/127.0.0.1:8080 - Connection refused 模拟器 ...
- telnet: connect to address 127.0.0.1: Connection refused
telnet协议是TCP/IP协议族中的一员,是Internet远程登陆服务的标准协议和主要方式.它为用户提供了在本地计算机上完成远程主机工作的能力.在终端使用者的电脑上使用telnet程序,用它连接 ...
- com.microsoft.sqlserver.jdbc.SQLServerException: 到主机 的 TCP/IP 连接失败。 java.net.ConnectException: Connection refused: connect
问题描述:最简单的数据库连接报错,到主机 的 TCP/IP 连接失败.(win 7 操作系统) 错误信息: com.microsoft.sqlserver.jdbc.SQLServerExcep ...
随机推荐
- linux 下 `dirname $0`(转)
在命令行状态下单纯执行 $ cd `dirname $0` 是毫无意义的.因为他返回当前路径的".".这个命令写在脚本文件里才有作用,他返回这个脚本文件放置的目录,并可以根据这个目 ...
- PRD、MRD、BRD的含义
一.PRD的含义 英文简称,PRD(Product Requirement Document),PRD文档中文意思是:产品需求文档. PRD文档是产品项目由“概念化”阶段进入到“图纸化”阶段的最主要的 ...
- C# 字符串转组件名、变量名
字符串转组件名 (Controls["button1"] as Button).Text = "Hello";//单独组件 (Controls[].Contro ...
- [转贴] 2016一月12日起.NET 4, 4.5 and 4.5.1 停止安全更新、技术支持 or hotfix
[转贴] 2016一月12日起.NET 4, 4.5 and 4.5.1 停止安全更新.技术支持 or hotfix https://www.dotblogs.com.tw/mis2000lab/20 ...
- 小记:iOS 中一般对于 view 不依赖 model 的的两种代码书写形式
一. 前言 对于在 MVC 的定义中,view 层是不引用 model 层,view 和 model 是不相往来的 一般开发中,我们都写过 在自定义 view 中增加一个 model 的属性,外接直接 ...
- RHEL7 本地yum源配置
配置yum 源 1.挂载DVD光盘到/mnt 因为配置时候路径名里面不能有空格,否则不能识别 [root@ mnt]# mount /dev/cdrom /mnt 2.在目录/etc/yum.r ...
- fold - 折叠输入行, 使其适合指定的宽度
总览 (SYNOPSIS) ../src/fold [OPTION]... [FILE]... 描述 (DESCRIPTION) 折叠(wrap) 每个 文件 FILE 中 的 输入行 (缺省为 标准 ...
- Python求列表中某个元素的下标
一.求列表中某个元素的下标 def findindex(org, x, pos=-1): counts = org.count(x) #先求出org中包含x的个数 if counts == 0: #个 ...
- ArrayList集合例题,商品库存管理(集合)
创建车库集合,存进车 public class demo1 { String pinpai; String c; int s; } import java.util.ArrayList; class ...
- android设备局域网中快速搜索之cling方式
cling方式就像pc端windows局域网工作组刷新显示一样,原来用过扫描ip地址的方式,可以使用就是有点慢,还有一种自己加入组广播,通过发送组广播的方式. android设备局域网中快速搜索之 ...