I am trying to connect to a PostgreSQL database in a virtual machine, through a php script, but being unsuccessful.
I execute the php from the host (Windows 8.1) and the postgresql is at the virtual machine (Debian 8.6). I use VirtualBox.
The error output from the browser is:
Warning: pg_connect(): Unable to connect to PostgreSQL server: could not connect to server: Connection timed out (0x0000274C/10060) Is the server running on host "10.0.2.15" and accepting TCP/IP connections on port 5432? in C:\xampp\htdocs\pg_test.php on line 11
with line 11 being
$host = "host=10.0.2.15";
$port = "port=5432";
$dbname = "dbname=postgres";
$user = "user=user_switch";
$password = "password=switch";
$conn_string = "$host $port $dbname $user $password";
host all all 0.0.0.0/0 trust
listen_addresses = '*'
-A INPUT -p tcp -m cp --dport 5432 -j ACCEPT
psql -d postgres -U user_switch -W -h localhost
Add this line to
host all all 10.0.2.0/24 trust
and restart PostgreSQL. This allows any connection to
10.0.2.x from any user.