Re: postgresql connection failure

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Ashley Sheridan
Date: Fri, 6 Aug 2021 20:16:34 +0100

> Couple of seconds Googling
the first error brings up a SO post where someone suggests editing your
postgresql.conf file adding the line:

listen_addresses = '*'

Thanks; perhaps 'duckduckgo'ing is not as accurate ;) assuming the search engine query result referred to is somewhere in that 'stackoverflow' web site...

Changed the configuration file to include:
"
listen_addresses = 'localhost'
"
For now, no password for database until php is learnt a bit more. So far, after this configuration file change, connection to the postgresql database continues to fail, but the previous error (sign-in to database via command terminal) is solved.

The php web page continues to return:
"
Generic CPAC database Could not connect
"

Please, any other ideas to follow?
--- Begin Message ---
On 06/08/2021 13:35, ourdiaspora wrote:
Readers,

After a day and half trying and failing, time to ask! :)

Command terminal:

sudo psql -d cpacweb -h localhost -U cpaca

psql: FATAL: no pg_hba.conf entry for host "::1", user "cpaca", database "cpacweb", SSL on

FATAL: no pg_hba.conf entry for host "::1", user "cpaca", database "cpacweb", SSL off

SHOW hba_file;

/etc/postgresql/9.6/main/pg_hba.conf

sudo nano /etc/postgresql/9.6/main/pg_hba.conf

local all postgres peer

TYPE DATABASE USER ADDRESS METHOD
=================================

"local" is for Unix domain socket connections only
==================================================

local all all peer

IPv4 local connections:
=======================

host all all 127.0.0.1/32 md5

IPv6 local connections:
=======================

host all all ::1/128 md5

Allow replication connections from localhost, by a user with the
================================================================

replication privilege.
======================

#local replication postgres peer

#host replication postgres 127.0.0.1/32 md5

#host replication postgres ::1/128 md5

local cpacweb cpaca ::1/128 trust

Also tried:

<html>

     <head>

     	Generic CPAC database
     </head>

     <body>

     	<?php
     		error_reporting(E_ALL);


pg_connect("host=localhost port=5432 dbname=cpacweb");

echo pg_dbname();

?>

     </body>


</html>

No success, but:

<html>

     <head>

     	Generic CPAC
     </head>

     <body>

     	<?php
     		//echo '<p>Hello World</p>'

     		/*successful test of configuration of apache http server*/
     		phpinfo();
     	?>

     </body>


</html>

returns a successful web page of system information details.

Please how to connect successfully to the postgresql database?


This looks to be more of a problem with your Postgres DB not allowing the connection than anything specific to PHP. Couple of seconds Googling the first error brings up a SO post where someone suggests editing your postgresql.conf file adding the line:

listen_addresses = '*'

However, I would recommend only allowing the addresses you actually know that should be connecting to this DB.

It also lists some advice about what changes you need to make to your pg_hba.conf to allow access for all users with an encrypted password, but you don't appear to actually be using a password on your database (none of your connection strings have one, and the error is about something else). I would always use a password for any DB, regardless of how locked down it may be in other areas.

--
Ashley Sheridan
https://www.ashleysheridan.co.uk



--- End Message ---

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux