0

I can connect to my database by running php via the bash:

php -r '$link=@pg_connect("host=fakehost.edu port=5432 dbname=db user=user password=totallynotthepassword");if($link){echo "connected";} else { echo "no dice";}' 

This results in a very happy "connected"

However, when I have the exact same PHP in a file served by Apache and go to that page, I get a very sad: "no dice"

Here is the code from the php file:

<html> <head> <title>PHP Test</title> </head> <body> <?php $link=@pg_connect("host=fakehost.edu port=5432 dbname=db user=user password=totallynotthepassword");if($link){echo "connected";} else { echo "no dice";} ?> </body> </html> 

I thought it had to do with the apache user, but i just tested the same code su'ed to that user and it connected.

    1 Answer 1

    2

    Looks like it was a security setting, which is fixed by running:

    sudo setsebool -P httpd_can_network_connect_db on 

    Found the answer here: https://stackoverflow.com/questions/37955681/pg-connect-php-script-works-from-command-line-but-not-from-web-page

      You must log in to answer this question.

      Start asking to get answers

      Find the answer to your question by asking.

      Ask question

      Explore related questions

      See similar questions with these tags.