1
votes

PHP: using PHP 5.3.10 on an ubuntu vm through Vagrant DB: Postgres 9.3.2.0

I can easily connect to a remote DB; however, when I try to connect to a local dev DB I have, I get an error

new PDO("pgsql:dbname=testdb;host=127.0.0.1;user=user1;password=tester;port=5432");

[Mon Jun 08 21:37:15 2015] [error] [client 10.0.2.2] PHP Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[08006] [7] could not connect to server: Connection refused\n\tIs the server running on host "127.0.0.1" and accepting\n\tTCP/IP connections on port 5432?' in /lib/Db.inc:28\nStack trace:\n#0 /lib/Db.inc(28): PDO->__construct('pgsql:dbname=te...')\n#1 /www/page1.php(9): Db->__construct('postgres://test...')\n#2 {main}\n thrown in /lib/Db.inc on line 28

I know this isn't a connection issue since my local db is up and running fine

psql postgres://user1:[email protected]/testdb
1
connection refused = nothing listening on that ip and/or port number, or a firewall is actively denying the connection by sending an icmp destination unreachable. - Marc B
Try removing the port or else try to port 3306 - Szenis
@Szenis PostgreSQL, not MySQL ;) - Jonnix
Can you psql into the server? Can you see it running in top / ps / netstat? This is sounding more like a config, and if so a serverfault question. - Jonnix
I can psql into the server just fine - user2158382

1 Answers

1
votes

I do running on Fedora 23 and after changing /var/lib/pgsql/data/pg_hba.conf from ident to md5 I was not able to connect with psql postgres://user1:[email protected]/testdb. Finally found out that selinux blocks the connection.

Quick fix is to edit /etc/selinux/config to disabled and reboot. But checking how to work with selinux and ports would be better solution.