X-Original-To: pgsql-php-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id B564F52808 for ; Thu, 18 Aug 2005 01:37:30 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 65010-01 for ; Thu, 18 Aug 2005 04:37:26 +0000 (GMT) Received: from zproxy.gmail.com (zproxy.gmail.com [64.233.162.205]) by svr1.postgresql.org (Postfix) with ESMTP id 0125C52A8A for ; Thu, 18 Aug 2005 01:37:24 -0300 (ADT) Received: by zproxy.gmail.com with SMTP id z6so218717nzd for ; Wed, 17 Aug 2005 21:37:24 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:references; b=fM4wnKx/Z4pSZTtkbtatXjD/u3K79U+g/CWpQtBaBRtjWljAuC+IicE5rerXYSPL5Fk8PSSDN+Wpl6uwklfXCDnJFIlpgoWHaWTarer4i//rVydQQG4UOzmyQq0so87bsZKXC0tu1xVZxvpE5qWqH6XEP6fW5i7xbGduAdZoobs= Received: by 10.36.221.9 with SMTP id t9mr545585nzg; Wed, 17 Aug 2005 21:37:24 -0700 (PDT) Received: by 10.36.119.19 with HTTP; Wed, 17 Aug 2005 21:37:24 -0700 (PDT) Message-ID: Date: Thu, 18 Aug 2005 10:07:24 +0530 From: Gnanavel S To: Hui Chen Subject: Re: Problem about connecting PostgreSQL through TCP/IP Cc: pgsql-php@postgresql.org In-Reply-To: <923c3c1405081410326a1c2880@mail.gmail.com> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_8920_26248182.1124339844595" References: <923c3c1405081410326a1c2880@mail.gmail.com> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.374 required=5 tests=[AWL=0.183, HTML_40_50=0.086, HTML_MESSAGE=0.001, NORMAL_HTTP_TO_IP=0.08, RCVD_BY_IP=0.024] X-Spam-Level: X-Archive-Number: 200508/21 X-Sequence-Number: 3233 ------=_Part_8920_26248182.1124339844595 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline On 8/14/05, Hui Chen wrote: >=20 > Hello, everyone, >=20 > Can anyone help me? I am quite frustrating now. I have been trying to > connect PostgreSQL server through TCP/IP connection using PHP. I was > not successful. Could please read the following and give me some > hints. Thanks a million. >=20 > OS: Fedora Core 4 ("uname -s -r" yields "Linux 2.6.12-1.1398_FC4smp") > PostgreSQL: version 8.0.3 > PHP: version 5.0.4 >=20 > In postgresql.conf, these three lines were inserted, > listen_addresses =3D '*' > port =3D 5432 > max_connections =3D 100 >=20 > The following lines were inserted to pg_hba.conf: > local all all password > host all all 127.0.0.1/32 password > host all all 192.168.0.0/1 password >=20 > restart posgresql by > /sbin/service postgresql restart > The server was restarted OK. >=20 > The PHP script used to connect database is as follows, > $conn =3D pg_connect("host=3Dlocalhost port=3D5432 dbname=3Dfoodb user=3D= foo > password=3Dfoo") or die ("Can not connect to postgres"); > $result=3Dpg_exec("SELECT * FROM footbl"); > $fetch =3D pg_fetch_row($result); > print ""; > print $fetch[0]; > print ""; >=20 > pg_close($conn); // Close this connection > ?> >=20 > Assume this PHP script is named as "connectdb.php", then on > commandline, when I run the following, > php connectedb.php > I see correct results, e.g., > foo >=20 > On commandline again, I used the following to connect database, > psql -d foodb -h localhost -p 5432 -U foo > Password: ************ Whether the password you typed here is "foo"? Welcome to psql 8.0.3, the PostgreSQL interactive terminal. >=20 > Type: \copyright for distribution terms > \h for help with SQL commands > \? for help with psql commands > \g or terminate with semicolon to execute query > \q to quit >=20 > foodb=3D> >=20 > It is OK. Then I disabled "iptables" temporarily for testing purpose by > /sbin/service iptables stop > Flushing firewall rules: [ OK ] > Setting chains to policy ACCEPT: filter [ OK ] > Unloading iptables modules: [ OK ] >=20 > On localhost, I tried this command, > telnet localhost 5432 > after hit "enters", telnet exited. I checked postgresql_%S.log and see > "LOG: invalid length of startup packet" > which means postgresql server indeed saw the telnet connection. >=20 > I tried this on any of my other machines in the LAN, I observed the same= =20 > thing. >=20 > In summary, it seemed the postgresql allowed TCP/IP connection, and > worked well. However, when I ran the PHP script through web browser, I > did not get connection. Instead, in Apache web server's error_log, I > see > [client 192.168.1.10 ] PHP Warning: pg_connect() [ href=3D'function.pg-connect'>function.pg-connect]: Unable to connect > to PostgreSQL server: could not connect to server: Permission > denied\n\tIs the server running on host "localhost" and > accepting\n\tTCP/IP connections on port 5432? in /foo/connectdb.php on > line 2 >=20 > Interestingly, when I checked the log file for postgresql again, it > did not have anything for this connection failure. It seemed the > connection did not send to the database server at all. However, > 1) I disabled firewall > 2) I can telnet the ports > 3) I can run the script from commandline >=20 > What could go wrong? >=20 > Thanks a lot for your reading this lengthy email. Waiting for your help! >=20 > Gray >=20 > ---------------------------(end of broadcast)--------------------------- > TIP 4: Have you searched our list archives? >=20 > http://archives.postgresql.org >=20 --=20 with regards, S.Gnanavel Satyam Computer Services Ltd. ------=_Part_8920_26248182.1124339844595 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline

On 8/14/05, Hui Chen <gray.che= nhui@gmail.com> wrote:
Hello, everyone,

Can anyone help me? I am quite frustrating now. I h= ave been trying to
connect PostgreSQL server through TCP/IP connection u= sing PHP. I was
not successful. Could please read the following and give= me some
hints. Thanks a million.

OS: Fedora Core 4 ("uname -s -r&qu= ot; yields "Linux 2.6.12-1.1398_FC4smp")
PostgreSQL: version 8= .0.3
PHP: version 5.0.4

In postgresql.conf, these three lines wer= e inserted,
listen_addresses =3D '*'
port =3D 5432
max_connections =3D 100
The following lines were inserted to pg_hba.conf:
local   all         all            =             &nb= sp;            =   password
host    all     &n= bsp;   all         127.0.0.1/32    &nb= sp;       password
host  &n= bsp; all         all         192.168.0.0/1    &= nbsp;     password

restart posgresql by
= /sbin/service postgresql restart
The server was restarted OK.

The= PHP script used to connect database is  as follows,
<?php
  $conn =3D pg_connect("host=3Dlocalhost por= t=3D5432 dbname=3Dfoodb user=3Dfoo
password=3Dfoo") or die ("C= an not connect to postgres");
   $result=3Dpg_exec("= SELECT * FROM footbl");
   $fetch =3D pg_fetch_row($result);
   print "= <html><body>";
   print $fetch[0];
 &= nbsp; print "<body></html>";

   pg_c= lose($conn); // Close this connection
?>

Assume this PHP script is named as "connectdb.php", then oncommandline, when I run the following,
     &= nbsp;           &nbs= p;    php connectedb.php
I see correct results, e.g.,
<html><body>f= oo<body></html>

On commandline again, I used the followi= ng to connect database,
psql -d foodb -h localhost -p 5432 -U foo
Password: ************
Whether the password you typed here= is "foo"?

Welcome= to psql 8.0.3, the PostgreSQL interactive terminal.

Type: &nbs= p;\copyright for distribution terms
       \h for help with SQL commands
&= nbsp;      \? for help with psql commands
 = ;      \g or terminate with semicolon to execute q= uery
       \q to quit

foodb=3D>=

It is OK. Then I disabled "iptables" temporarily for test= ing purpose by
/sbin/service iptables stop
Flushing firewall rules:           &nb= sp;            =            [  OK  ]
Setting chains to policy ACCEPT: filter           &nb= sp;        [  OK &nb= sp;]
Unloading iptables modules:           &= nbsp;           &nbs= p;        [  OK &nbs= p;]

On localhost, I tried this command,
telnet localhost 5432
= after hit "enters", telnet exited. I checked postgresql_%S.log an= d see
"LOG:  invalid length of startup packet"
which means postgresql server indeed saw the telnet connection.

= I tried this on any of my other machines in the LAN, I observed the same th= ing.

In summary, it seemed the postgresql allowed TCP/IP connection,= and
worked well. However, when I ran the PHP script through web browser, I<= br>did not get connection. Instead, in Apache web server's error_log, I
= see
[client 192.168.1.10] PHP Warnin= g:  pg_connect() [<a
href=3D'function.pg-connect'>function.pg-connect</a>]: Unable = to connect
to PostgreSQL server: could not connect to server: Permission=
denied\n\tIs the server running on host &quot;localhost&quot; a= nd
accepting\n\tTCP/IP connections on port 5432? in /foo/connectdb.php on<= br>line 2

Interestingly, when I checked the log file for postgresql = again, it
did not have anything for this connection failure. It seemed t= he
connection did not send to the database server at all. However,
1) I= disabled firewall
2) I can telnet the ports
3) I can run the script = from commandline

What could go wrong?

Thanks a lot for your r= eading this lengthy email. Waiting for your help!

Gray

---------------------------(end of broadcast)----------= -----------------
TIP 4: Have you searched our list archives?

&nb= sp;            =   http://archives.postgresq= l.org



--
with regards,S.Gnanavel
Satyam Computer Services Ltd. ------=_Part_8920_26248182.1124339844595--