5

EDIT: I just realized that this question may be better suited to ServerFault. Instead of copying it, a moderator please move it over? Thanks.

I've checked php-info, and the Postgresql extension is there (pg_connect() is not undefined). I am also able to connect to postgresql using psql on localhost (I've edited my pg_hba.conf file appropriately). Here is the code that's not working:

<?php
$dbconn = pg_connect("host=localhost port=5432 dbname=mydb user=myuser password=mypass") or die('Could not connect: ' . pg_last_error());
?>

This code simply results in "Could not connect: " being displayed in the browser.

I checked my apache log, and here's the relevant error message:

PHP Warning:  pg_connect() [<a href='function.pg-connect'>function.pg-connect</a>]: 
Unable to connect to PostgreSQL server: could not connect to server: Permission 
denied\n\tIs the server running on host &quot;localhost&quot; and accepting\n\tTCP/IP 
connections on port 5432?

How can I fix/debug this?

Edit: I'm on Centos 5.4 btw.

1 Answer 1

10

could not connect to server: Permission denied

Edit: I'm on Centos 5.4 btw.

Check /var/log/audit/audit.log. Chances are that you're hitting a SELinux rule.

1
  • 2
    Thanks, that was it. I just did setenforce 0 and it worked.
    – ehsanul
    Aug 14, 2010 at 3:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.