• 14

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 187


File: /home/prodcxja/public_html/questions/application/views/question.php
Line: 187
Function: _error_handler

File: /home/prodcxja/public_html/questions/application/controllers/Questions.php
Line: 433
Function: view

File: /home/prodcxja/public_html/questions/index.php
Line: 315
Function: require_once

name Punditsdkoslkdosdkoskdo

PHP can't connect to PostgreSQL on CentOS 7

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:

Warning: pg_connect(): Unable to connect to PostgreSQL server: could not connect to server: Permission denied Is the server running on host "" and accepting TCP/IP connections on port 5432? in /var/www/html/pg.php on line 7


  • Apache is running
  • PHP is fine, phpinfo() tells me PostgreSQL functions are available
  • PostgreSQL 9.2 is running
  • psql can connect to the database using localhost or and also
  • pgAdmin on my Mac can connect to this database using ip address
  • iptables has been turned off
  • pg_hba.conf has been changed to accept all connections without any password (stupid, I know):

host all all trust

But php can't connect.... This is my script:

ini_set('display_errors', 1);

echo 'hello world!';

$conn = pg_connect('host= port=5432 user=postgres dbname=postgres');

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?

Probably SELinux is blocking your database connection.

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
  • 14
Reply Report