Thread: Cannot connect to remote postgres using php

Cannot connect to remote postgres using php

From
Archana K N
Date:

Hello,

       I am getting this error whenever I try to connect to remote computer.
"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.162.19.3" and accepting TCP/IP connections on port 5432?  "
--
-------------------
regards
archana
--------------------

Re: Cannot connect to remote postgres using php

From
Hartmut Holzgraefe
Date:
On 04/30/2012 10:30 AM, Archana K N wrote:
> Hello,
>
>        I am getting this error whenever I try to connect to remote computer.
> "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.162.19.3" and accepting TCP/IP connections on port
> 5432?  "

there's most likely a firewall in between that drops packages ...

--
hartmut

Re: Cannot connect to remote postgres using php

From
Narongdetch Jongjit
Date:
Dear Archana,


Sorry! Why did you ask me?

Best Regards,
Narongdetch Jongjit


Date: Mon, 30 Apr 2012 14:00:22 +0530
Subject: [PHP] Cannot connect to remote postgres using php
From: archanakknn@gmail.com
To: pgsql-php@postgresql.org


Hello,

       I am getting this error whenever I try to connect to remote computer.
"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.162.19.3" and accepting TCP/IP connections on port 5432?  "
--
-------------------
regards
archana
--------------------

Re: Cannot connect to remote postgres using php

From
"Dimitris Sakellarios"
Date:

Dear Archana hi,

 

Follow below:

 

Step0

Make sure you have no firewall between you (php server root ip) and the server that blocks requests.

 

If this is OK then:

 

Step1   

Inside postgresql.conf make sure you have set the listen IP and listen port of your server and this will be the port you connect with php pg_connect

 

Step2

Inside pg_hda.conf configure the hosts you will allow connection either as trusted or md5

 

Typically bellow will allow all to connect

 

hostnossl    all         all         0.0.0.0/0          trust

 

Below will allow all to connect using username and password (but before have the first rule enabled to create remotely the users)

 

hostnossl    all         all         0.0.0.0/0          md5

 

Step3    restart Pgsql server to grand the new setting.

 

BR,

 

 

Sakellarios Dimitris

Telesuite ltd Telecommunication and Internet Services

Address : T. Sofouli 14, Post Code 16344, Ilioupoli - Athens, Greece

T.: +30 211 760 1300 F.: +30 211 176 9999 M.: +30 6982 550 850 e-mail: dimitris.sakellarios@telesuite.gr  url: http://www.telesuite.gr


From: pgsql-php-owner@postgresql.org [mailto:pgsql-php-owner@postgresql.org] On Behalf Of Archana K N
Sent: Monday, April 30, 2012 11:30 AM
To: pgsql-php@postgresql.org
Subject: [PHP] Cannot connect to remote postgres using php

 


Hello,

       I am getting this error whenever I try to connect to remote computer.
"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.162.19.3" and accepting TCP/IP connections on port 5432?  "
--
-------------------
regards
archana
--------------------

Re: Cannot connect to remote postgres using php

From
Sven Marcel Buchholz
Date:
On 30.04.12 10:30, Archana K N wrote:
>
> Hello,
>
>        I am getting this error whenever I try to connect to remote
> computer.
> "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.162.19.3" and accepting TCP/IP connections
> on port 5432?  "
> --
> -------------------
> regards
> archana
> --------------------
Hello,

did your DB-Server accept connections via TCP/IP, can you connect via psql?

regards
Sven

Re: Cannot connect to remote postgres using php

From
Raymond O'Donnell
Date:
On 30/04/2012 09:30, Archana K N wrote:
>
> Hello,
>
>        I am getting this error whenever I try to connect to remote computer.
> "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.162.19.3" and accepting TCP/IP connections on
> port 5432?  "

Things to check:

- Is Postgres actually running on the server machine?

- Is it accepting TCP/IP connections on port 5432? - Check
listen_addresses in postgresql.conf

- Is there a firewall somewhere between client and server?

- Can you connect manually to the server using psql?

Ray.


--
Raymond O'Donnell :: Galway :: Ireland
rod@iol.ie

Re: Cannot connect to remote postgres using php

From
Archana K N
Date:

Hello,

 I can connect to the other computer using web browser and also can access postgres.



--
-------------------
regards
archana
--------------------

Re: Cannot connect to remote postgres using php

From
Raymond O'Donnell
Date:
On 30/04/2012 11:01, Archana K N wrote:
>
> Hello,
>
>  I can connect to the other computer using web browser and also can
> access postgres.

How exactly are you access Postgres? - psql, pgAdmin, or some other means?

Also, a *lot* more detail would help.... operating systems, Postgres
version, PHP version, whether you're connection on a LAN or over the
Internet, etc etc etc.

Ray.

--
Raymond O'Donnell :: Galway :: Ireland
rod@iol.ie

Re: Cannot connect to remote postgres using php

From
"Dimitris Sakellarios"
Date:

Dear archana,

 

Is the PHP script you are running on a remote server other than the one running Pgsql?

 

If so, have you got rights to access Pgsql server remotely? Or you are allowed only from a web browser using phpmyadmin?

 

Are you the admin of Pgsql server?

 

---------

 

Did you try pgAdmin3 as a standalone client to connect from your pc?

 

Please provide some topology design.

 

 

Sakellarios Dimitris

Telesuite ltd Telecommunication and Internet Services

Address : T. Sofouli 14, Post Code 16344, Ilioupoli - Athens, Greece

T.: +30 211 760 1300 F.: +30 211 176 9999 M.: +30 6982 550 850 e-mail: dimitris.sakellarios@telesuite.gr  url: http://www.telesuite.gr


From: pgsql-php-owner@postgresql.org [mailto:pgsql-php-owner@postgresql.org] On Behalf Of Archana K N
Sent: Monday, April 30, 2012 1:02 PM
To: pgsql-php@postgresql.org
Subject: Re: [PHP] Cannot connect to remote postgres using php

 


Hello,

 I can connect to the other computer using web browser and also can access postgres.



--
-------------------
regards
archana
--------------------

Re: Cannot connect to remote postgres using php

From
"Dimitris Sakellarios"
Date:

If you are admin of Pgsql server pls provide

 

pg_hda.conf

postgresql.conf

 

maybe the configuration of your server doesn’t allow connection other that local host.

 

 

Sakellarios Dimitris

Telesuite ltd Telecommunication and Internet Services

Address : T. Sofouli 14, Post Code 16344, Ilioupoli - Athens, Greece

T.: +30 211 760 1300 F.: +30 211 176 9999 M.: +30 6982 550 850 e-mail: dimitris.sakellarios@telesuite.gr  url: http://www.telesuite.gr


From: pgsql-php-owner@postgresql.org [mailto:pgsql-php-owner@postgresql.org] On Behalf Of Dimitris Sakellarios
Sent: Monday, April 30, 2012 1:11 PM
To: 'Archana K N'; pgsql-php@postgresql.org
Subject: Re: [PHP] Cannot connect to remote postgres using php

 

Dear archana,

 

Is the PHP script you are running on a remote server other than the one running Pgsql?

 

If so, have you got rights to access Pgsql server remotely? Or you are allowed only from a web browser using phpmyadmin?

 

Are you the admin of Pgsql server?

 

---------

 

Did you try pgAdmin3 as a standalone client to connect from your pc?

 

Please provide some topology design.

 

 

Sakellarios Dimitris

Telesuite ltd Telecommunication and Internet Services

Address : T. Sofouli 14, Post Code 16344, Ilioupoli - Athens, Greece

T.: +30 211 760 1300 F.: +30 211 176 9999 M.: +30 6982 550 850 e-mail: dimitris.sakellarios@telesuite.gr  url: http://www.telesuite.gr


From: pgsql-php-owner@postgresql.org [mailto:pgsql-php-owner@postgresql.org] On Behalf Of Archana K N
Sent: Monday, April 30, 2012 1:02 PM
To: pgsql-php@postgresql.org
Subject: Re: [PHP] Cannot connect to remote postgres using php

 


Hello,

 I can connect to the other computer using web browser and also can access postgres.



--
-------------------
regards
archana
--------------------

Re: Cannot connect to remote postgres using php

From
Raymond O'Donnell
Date:
On 30/04/2012 11:15, Archana K N wrote:
>
>
> I am using dreamweaver for creating web pages and requires php for
> connecting to server computerand database . Am also using pgadmin but
> can connect using that.
>
> Postgresql version-  9.
> Operating System- windows XP
> php version-5.2
> apache - 2.2
> and am using LAN

Hi Arachna,

[Please keep replies on-list; reply-all should do the job. Thanks!]

Is it possible that your Postgres server is listening on a different
port? If you can, could you post your postgresql.conf?

Also, are you maybe using a firewall locally on your Windows machine
which is blocking PHP?

Ray.

--
Raymond O'Donnell :: Galway :: Ireland
rod@iol.ie

Re: Cannot connect to remote postgres using php

From
"Dimitris Sakellarios"
Date:

Hi,

 

When you changed the 2 files did you restart the Pgsql server? If not do it.

 

Where is the pgadmin3 installed on the same computer running the Pgsql server or on a remote computer?

If it is on the same server default behaviour of Pgsql server is to allow connection from the same server (local host) but if it is remotely then either you will need to update the 2 files we mentioned earlier correctly.

 

Let me know.

 

 

Sakellarios Dimitris

Telesuite ltd Telecommunication and Internet Services

Address : T. Sofouli 14, Post Code 16344, Ilioupoli - Athens, Greece

T.: +30 211 760 1300 F.: +30 211 176 9999 M.: +30 6982 550 850 e-mail: dimitris.sakellarios@telesuite.gr  url: http://www.telesuite.gr


From: Archana K N [mailto:archanakknn@gmail.com]
Sent: Monday, April 30, 2012 1:20 PM
To: Dimitris Sakellarios
Subject: Re: [PHP] Cannot connect to remote postgres using php

 

hello,

     I have changed both conf files. It is not working.


--
-------------------
regards
archana
--------------------

 

From: Archana K N [mailto:archanakknn@gmail.com]
Sent: Monday, April 30, 2012 1:20 PM
To: Dimitris Sakellarios
Subject: Re: [PHP] Cannot connect to remote postgres using php

 



Yes my php script is running on a computer other than pgsql.

yes logged in as admin in pgsql.

I am using pgadmin 3 also. I can connect using pgadmin.

--
-------------------
regards
archana
--------------------

Re: Cannot connect to remote postgres using php

From
Archana K N
Date:
My postgres server is listening to same port . I tried changing both but same error is showing. 

I restarted the servers after changing the conf files. pgadmin3 is running on both servers and i can connect them remotely. I am able to connect to local host using the php code.

I think i have changed the files correctly , some antivirus softwares are running in the system i dont know whether that causes the problem.


--
-------------------
regards
archana
--------------------

Re: Cannot connect to remote postgres using php

From
Sven Marcel Buchholz
Date:
On 30.04.12 17:57, Archana K N wrote:
> My postgres server is listening to same port . I tried changing both
> but same error is showing.
>
> I restarted the servers after changing the conf files. pgadmin3 is
> running on both servers and i can connect them remotely. I am able to
> connect to local host using the php code.
>
> I think i have changed the files correctly , some antivirus softwares
> are running in the system i dont know whether that causes the problem.
>
>
> --
> -------------------
> regards
> archana
> --------------------
Hallo,

did yours server listens on other addresses than localhost (I mean the
parameter listen_addresses in your postgresql.conf)?

Kind regards

Sven

Re: Cannot connect to remote postgres using php

From
Archana K N
Date:


listen_addresses is given as  ' * ' . Didnt try it on other addresses.


--
-------------------
regards
archana
--------------------

Re: Cannot connect to remote postgres using php

From
"sven@is-buchholz.com"
Date:

 


Archana K N <archanakknn@gmail.com> hat am 30. April 2012 um 18:16 geschrieben:

> listen_addresses is given as  ' * ' . Didnt try it on other addresses.
>
>
> --
> -------------------
> regards
> archana
> --------------------

Hallo,

 

ok, do you use the same db-user for pgAdmin3 and your php-script? 

Re: Cannot connect to remote postgres using php

From
"Dimitris Sakellarios"
Date:

First of all set all firewall down and then test again.

 

I remember you said that the PHP server and the PGSQL server are on different machines? Is that correct?

 

If so how did you succeed to connect to local host? Did you move your PHP code to the same machine hosting your PGSQL server or do you host a PGSQL server on both machines?

 

Provide some more details (a small design) to give more help else it is hopeless like that sorry. Also provide the the part of the PHP you try to create the connection.

 

Try the below proposal.

 

On server that host the PHP (IP=y.y.y.y)

 

<?php

….

pg_connect("host=x.x.x.x port=5432 dbname=AAAAAAA user=BBBBBBBB password=BBBBBBBB") or die('Could not connect: ' . pg_last_error());

….

?>

 

On server that host PGSQL (IP=x.x.x.x)

 

Inside pg_hba.conf

 

hostnossl    all         all         0.0.0.0/0          trust

….

 

Inside postgresql.conf

 

listen_addresses = 'x.x.x.x,localhost'

port = 5432

 

Test and report.

 

BR,

 

 

Sakellarios Dimitris

Telesuite ltd Telecommunication and Internet Services

Address : T. Sofouli 14, Post Code 16344, Ilioupoli - Athens, Greece

T.: +30 211 760 1300 F.: +30 211 176 9999 M.: +30 6982 550 850 e-mail: dimitris.sakellarios@telesuite.gr  url: http://www.telesuite.gr


From: pgsql-php-owner@postgresql.org [mailto:pgsql-php-owner@postgresql.org] On Behalf Of Archana K N
Sent: Monday, April 30, 2012 6:58 PM
To: pgsql-php@postgresql.org
Subject: Re: [PHP] Cannot connect to remote postgres using php

 

My postgres server is listening to same port . I tried changing both but same error is showing. 

 

I restarted the servers after changing the conf files. pgadmin3 is running on both servers and i can connect them remotely. I am able to connect to local host using the php code.

 

I think i have changed the files correctly , some antivirus softwares are running in the system i dont know whether that causes the problem.

 

--
-------------------
regards
archana
--------------------

Re: Cannot connect to remote postgres using php

From
Archana K N
Date:


I host pgsql servers on both machines.
the pph code is like this



'

$conn=pg_connect("host=10.162.19.3 port=5432 dbname=postgres user=postgres password=postgresql");

'



--
-------------------
regards
archana
--------------------

Re: Cannot connect to remote postgres using php

From
Sven Marcel Buchholz
Date:
On 30.04.12 20:10, Archana K N wrote:


I host pgsql servers on both machines.
the pph code is like this



'

$conn=pg_connect("host=10.162.19.3 port=5432 dbname=postgres user=postgres password=postgresql");

'



--
-------------------
regards
archana
--------------------
Hallo,

your firewall accepts requests for the IP 10.162.19.3 on port 5432?

Kind regards

Sven