X-Original-To: pgsql-php-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id A9AA252BC1 for ; Sun, 14 Aug 2005 14:32:58 -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 00369-07 for ; Sun, 14 Aug 2005 17:32:57 +0000 (GMT) Received: from wproxy.gmail.com (wproxy.gmail.com [64.233.184.196]) by svr1.postgresql.org (Postfix) with ESMTP id E9D4852F7D for ; Sun, 14 Aug 2005 14:32:55 -0300 (ADT) Received: by wproxy.gmail.com with SMTP id i22so861435wra for ; Sun, 14 Aug 2005 10:32:56 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition; b=qolZsFovcXtGFQeCWi7Af/E75txL4u/4K5V3XAdphAUYWO26I151SOU6YmHrxzPk7yjHPxe4H+ewD5H2Qf99DnaHmZCKfVYa2ANxw9SXmmY55BzpwlB/KNwV78KduSVz07QLISFOgszRZiqJpOG03wfghMyM2MLKSsGqBFWjdhY= Received: by 10.54.69.1 with SMTP id r1mr3156317wra; Sun, 14 Aug 2005 10:32:56 -0700 (PDT) Received: by 10.54.98.9 with HTTP; Sun, 14 Aug 2005 10:32:56 -0700 (PDT) Message-ID: <923c3c1405081410326a1c2880@mail.gmail.com> Date: Sun, 14 Aug 2005 12:32:56 -0500 From: Hui Chen To: pgsql-php@postgresql.org Subject: Problem about connecting PostgreSQL through TCP/IP Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.024 tagged_above=0 required=5 tests=[RCVD_BY_IP=0.024] X-Spam-Level: X-Archive-Number: 200508/1 X-Sequence-Number: 3213 Hello, everyone, 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. 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 In postgresql.conf, these three lines were inserted,=20 listen_addresses =3D '*' =20 port =3D 5432 max_connections =3D 100 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 restart posgresql by=20 /sbin/service postgresql restart The server was restarted OK. The PHP script used to connect database is as follows, "; print $fetch[0]; print ""; 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.,=20 foo=20 On commandline again, I used the following to connect database, psql -d foodb -h localhost -p 5432 -U foo Password: ************ Welcome to psql 8.0.3, the PostgreSQL interactive terminal. 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 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 ] 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 th= ing.=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() [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 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 What could go wrong? Thanks a lot for your reading this lengthy email. Waiting for your help! Gray