[GIS] How to connect Postgis database with/in Remote Servers…

geoserverpostgis-2.0

I am preparing a 'Web based map' application using 'Geoserver-Openlayers-Postgis'.

I am trying to connect my Postgis database(located at 10.50.110.11 location) with the following command from 10.40.48.22 location….


$host = 'localhost/10.50.110.11';
$port = '5432';
$database = 'template_postgis_20';
$user = 'postgres';
$password = 'user';

$connectString = 'host=' . $host . ' port=' . $port . ' dbname=' . $database .
' user=' . $user . ' password=' . $password;

$link = pg_connect($connectString);
if (!$link)
{
die('Error: Could not connect: ' . pg_last_error());
echo "Could NOT connect POSTGRES…";
}


This is yielding a blank response.

Best Answer

The command should have been:

$host = '10.50.110.11'; $port = '5432'; $database = 'template_postgis_20'; $user = 'postgres'; $password = 'user';

You also need to set your server to listen to connections from interfaces. To do this, change the listen_addresses in your postgresql.conf file from 127.0.0.1 to *.

You might also want to check your pg_hba.conf. See if it allows addresses other than localhost to connect.

Sources: StackExchange thread on Postgresql