title: Can't Connect to PostgreSQL with PHP pg_connect()
body: <p>EDIT: I just realized that this question may be better suited to ServerFault. Instead of copying it, a moderator please move it over? Thanks.</p>
  
  <p>I've checked php-info, and the Postgresql extension is there (<code>pg_connect()</code> is not undefined). I am also able to connect to postgresql using <code>psql</code> on localhost (I've edited my pg_hba.conf file appropriately). Here is the code that's not working:</p>
  
  <pre><code>&lt;?php
  $dbconn = pg_connect("host=localhost port=5432 dbname=mydb user=myuser password=mypass") or die('Could not connect: ' . pg_last_error());
  ?&gt;
  </code></pre>
  
  <p>This code simply results in "Could not connect: " being displayed in the browser.</p>
  
  <p>I checked my apache log, and here's the relevant error message:</p>
  
  <pre><code>PHP Warning:  pg_connect() [&lt;a href='function.pg-connect'&gt;function.pg-connect&lt;/a&gt;]: 
  Unable to connect to PostgreSQL server: could not connect to server: Permission 
  denied\n\tIs the server running on host &amp;quot;localhost&amp;quot; and accepting\n\tTCP/IP 
  connections on port 5432?
  </code></pre>
  
  <p>How can I fix/debug this?</p>
  
  <p>Edit: I'm on Centos 5.4 btw.</p>