I have set up a test server and installed PHP 5.4 (zend Server with Nginx) and also postgresql 9.1.
I am trying to connect to the postgresql database using the following code:
define('DB_TYPE', 'pgsql');
define('DB_HOST', 'localhost');
define('DB_PORT', 5432);
define('DB_NAME', 'rockprofile');
define('DB_USERNAME', 'rockprofile');
define('DB_PASSWORD', 'PASSWORD');
$dsn = DB_TYPE . ':dbname=' . DB_NAME . ';host=' . DB_HOST . ';port=' . DB_PORT;
try {
$db = new PDO($dsn, DB_USERNAME, DB_PASSWORD);
} catch (PDOException $e) {
echo $e->getMessage();
print_r($e->getTrace());
}
However this is generating the following:
SQLSTATE[08006] [7] FATAL: Ident authentication failed for user "rockprofile"
Array (
[0] => Array (
[file] => /usr/share/nginx/inc/config.php
[line] => 24
[function] => __construct
[class] => PDO
[type] => -> [args] => Array (
[0] => pgsql:dbname=rockprofile;host=localhost;port=5432
[1] => rockprofile
[2] => PASSWORD ) )
[1] => Array ( [file] => /usr/share/nginx/bands/index.php
[line] => 2
[args] => Array (
[0] => /usr/share/nginx/inc/config.php )
[function] => include ) )
As you can see I am using localhost. I know the dsn is correct including the username and password because if I substitute localhost with the local 192 IP it works. I suspect this is an issue with the configuration of postgresql and the following is the current content:
local all all peer
host all all 127.0.0.1/32 ident
host all all ::1/128 ident
host all all 192.168.1.0/24 md5
On searching someone appeared to resolve this by changing ident to trust on the config above but this has not helped in my case.
It is probably something simple I need to add but searches seem to be fruitless at the moment. Can anyone tell me how to correct this.
*-----EDIT-----*
As per Daniel Vérité's response to fix the issue ident needs to be changed to MD5. I personally had to change this for both the IPv4 and IPv6 entries.
local all all peer
host all all 127.0.0.1/32 md5
host all all ::1/128 md5
host all all 192.168.1.0/24 md5
127.0.0.1