PHP & PostgreSQL Woes, Part Four
First up, let me ensure that I've restored all the configuration files to their original state...
[tdavis@basement ~]$ su Password: [root@basement tdavis]# cd /var/lib/pgsql/data/ [root@basement data]# cp pg_hba.conf.original pg_hba.conf cp: overwrite `pg_hba.conf'? y [root@basement data]# cp pg_ident.conf.original pg_ident.conf cp: overwrite `pg_ident.conf'? y
Check.
And a little restart...
[root@basement data]# /sbin/service postgresql restart Stopping postgresql service: [ OK ] Starting postgresql service: [ OK ]
Check.
A little review of my test script...
[tdavis@basement 050609]$ cat insert.php
<?php
ini_set('display_errors',true);
$dbconn=pg_connect("dbname=basement user=tdavis password=pokesmot");
$rset=pg_query($dbconn,"select * from users");
$array=pg_fetch_array($rset);
echo $array["username"];
echo "\n";
pg_close($dbconn);
?>
... and make sure it runs (it should print "tdavis")...
[tdavis@basement 050609]$ php insert.php Content-type: text/html X-Powered-By: PHP/4.3.11 tdavis
Bingo!
Now let's load it up from the web...
Warning: pg_connect(): Unable to connect to PostgreSQL server: could not connect to server: Permission denied Is the server running locally and accepting connections on Unix domain socket "/tmp/.s.PGSQL.5432"? in /home/tdavis/public_html/050609/insert.php on line 3
Warning: pg_query(): supplied argument is not a valid PostgreSQL link resource in /home/tdavis/public_html/050609/insert.php on line 4
Warning: pg_fetch_array(): supplied argument is not a valid PostgreSQL result resource in /home/tdavis/public_html/050609/insert.php on line 5
Warning: pg_close(): supplied argument is not a valid PostgreSQL link resource in /home/tdavis/public_html/050609/insert.php on line 8
Curses!
Considering that it works from the command line but not from the web, I'm pretty confident that this is an 'ident' issue with PostgreSQL authentication. Essentially, the tdavis Unix account can connect to the tdavis database account, but the apache Unix account may not.
First I'll try the suggestion Larry Klug posted: changing 'ident' to 'trust', which essentially means "let anybody log in"...
[root@basement data]# diff pg_hba.conf pg_hba.conf.original 66c66 < local all all trust --- > local all all ident sameuser
... and another restart...
[root@basement data]# /sbin/service postgresql restart Stopping postgresql service: [ OK ] Starting postgresql service: [ OK ]
... and a hit from the browser...
BAM! Same error.
Warning: pg_connect(): Unable to connect to PostgreSQL server: could not connect to server: Permission denied Is the server running locally and accepting connections on Unix domain socket "/tmp/.s.PGSQL.5432"? in /home/tdavis/public_html/050609/insert.php on line 3
Warning: pg_query(): supplied argument is not a valid PostgreSQL link resource in /home/tdavis/public_html/050609/insert.php on line 4
Warning: pg_fetch_array(): supplied argument is not a valid PostgreSQL result resource in /home/tdavis/public_html/050609/insert.php on line 5
Warning: pg_close(): supplied argument is not a valid PostgreSQL link resource in /home/tdavis/public_html/050609/insert.php on line 8
Round and round she goes. Where she stops, nobody knows!
