0
I’m trying to remotely connect postgresql to PHP on an Apache server. On my local machine I can run the connection without any problem. The point is that it is not working remotely.
I’m running the same code that ran on another instance of the same service cloud (changing only the IP). No error message is appearing and no code message appears indicating that the database has not been connected. I’m using an Ubuntu server 14.04. Could someone help me? I’m not finding the problem!
Checked:
- Postgresql MV configuration by psql via SSH connection and Pgadmin3 remotely. Both working perfectly.
- Definition of the ok password.
- pg_hba.conf configuration (as indicated in the contracted cloud service tutorial)
# Ipv4 remote Connections (all users and IP Addresses): host all all 0.0.0.0/0 md5
Configuration of postgresql.conf (as indicated in the tutorial of the contracted cloud service)
listen_addresses = '*'
Firewall rules - ok.
PHP code (the same code works perfectly on the local machine and worked in another instance of the same cloud service).
<?php $host = "host=xx.xx.xx.xx"; $port = "port=5432"; $dbname = "dbname=nomedabasededados"; $credentials = "user=postgres password=senha"; $db = pg_connect( "$host $port $dbname $credentials" ); if(!$db){ echo "Error : Unable to open database\n"; } $sql = pg_query("INSERT INTO tabela (coluna1) VALUES ('valordacoluna1');"); ?>
Tried to check if the port is open from another server?
– Andre Mesquita
Dear @Andre Mesquita, thank you so much for the tip. How could I check if the door is open? I can enter the data directly from my psql or pgadmin3, this indicates that port 5432 is open?
– M.Dev
Dear @Andremesquita, through the nmap command I got: 22/tcp, 80/tcp hhtp, 5432/tcp to postgresql. You could tell me how to check from another server?
– M.Dev
nmap itself. instead of using localhost, use the IP of your postgresql server. If ping is blocked, you can use the -np parameter.
– Andre Mesquita
Dear @Andremesquita, I was able to verify with the command you indicated to me. I have obtained that ports 22 (ssh), 80 (http) and 5432 (postgresql) are open and ports 443 (https) and 3389 (ms-wbt-server) are closed. You believe that one of the closed doors may be damaging the connection with the postgres?
– M.Dev
No. I don’t quite remember postgresql, but in mysql the user has a designation that indicates if it can be accessed from outside. Take a look at this Article that can guide you.
– Andre Mesquita
There’s this other article that the boy explains about the permissions. I hope it helps.
– Andre Mesquita
Thank you @Andremesquita
– M.Dev
which cloud service ?
– Rovann Linhalis