Wednesday, January 23, 2013

SELinux cause PostgreSQL error: could not connect to server: Permission denied

The php command line works but not the apache page.

Error message:

pg_connect(): Unable to connect to PostgreSQL server: could not connect to server: Permission deniednt
Is the server running on host "localhost" (::1) and acceptingnt
TCP/IP connections on port 5432?ncould not connect to server: Permission deniednt
Is the server running on host "localhost" (127.0.0.1) and acceptingnt
TCP/IP connections on port 5432? in /home/www/htdocs/test.php on line 3


If you don't want to be using SELinux then disabling it is an option, but if you prefer the other protection it offers you may just want to enable the specific permission to allow Apache to issue HTTP connections.

As root, running:

# service httpd stop
# service postgresql-9.2 stop

# setsebool -P httpd_can_network_connect 1

# service httpd start
# service postgresql-9.2 start

6 comments:

  1. I'm amazed, I must say. Seldom do I encounter a blog that's equally educative and engaging, and without a doubt, you've hit the nail on the head. The problem is something that not enough men and women are speaking intelligently about. I'm very happy that I found this during my search for something relating to this.|

    ReplyDelete
  2. Excellent blog here! Also your web site loads up fast! What host are you using? Can I get your affiliate link to your host? I wish my website loaded up as quickly as yours lol

    ReplyDelete
  3. Hello there, I discovered your site by the use of Google at the same time as looking for a related subject, your site got here up, it appears good. I've added to my favourites|added to my bookmarks.

    ReplyDelete
  4. That's really attention-grabbing, You're an excessively specialist blogger. We've become a member of your current rss and appearance onward to be able to with mission of additional of the outstanding article. As well, I have provided your website at my web sites

    ReplyDelete
  5. Thanks a lot for the information
    it was really useful
    we stayed for long hours looking for this.

    ReplyDelete
  6. Everyone is saying so and YES, it helped (I've been kind of looking for it for few weeks now - no jokes)

    Thanks much!

    ReplyDelete