I have CentOS 7 running in VirtualBox on OSX. Apache, PHP 5.4 and PostgreSQL 9.2 are all running. But, when my (simple) php-script tries to connect to PostgreSQL it doesn't work:
Warning: pg_connect(): Unable to connect to PostgreSQL server: could not connect to server: Permission denied Is the server running on host "127.0.0.1" and accepting TCP/IP connections on port 5432? in /var/www/html/pg.php on line 7
Checks:
host all all 0.0.0.0/0 trust
But php can't connect.... This is my script:
<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
echo 'hello world!';
$conn = pg_connect('host=127.0.0.1 port=5432 user=postgres dbname=postgres');
?>
Internal connections work (psql), external connections also work (pgAdmin on a my laptop), but the php connection doesn't work...
What is going wrong? What is it that I'm missing?
Probably SELinux is blocking your database connection.
Make sure that you set the correct boolean to allow your web application to talk to the database:
sudo setsebool -P httpd_can_network_connect_db 1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With