Thread: Not able to connect to server from PHP

Not able to connect to server from PHP

From
Jeff Self
Date:
I'm working on a personnel database for my department. I can connect
just fine using 'psql personnel'. I've created a PHP script to get a
list of departments, but I'm getting the following error message:

Warning: Unable to connect to PostgreSQL server: Peer authentication
failed for user 'jeff' in /var/www/personnel/departments.php on line 10
Unable to connect to database.

Here's my script:
<?php
//
// Display Departments
//
// departments.php, v 1.0

include ($DOCUMENT_ROOT.'/personnel/include/functions.inc');

$conn = pg_pconnect("dbname=personnel user=jeff");
if (!$conn) {
    echo "Unable to connect to database.";
    exit;
}

Everything is running locally right now, Apache, PHP, PostgreSQL. I
never modified my pg_hba.conf file. Everything looks identical as my
system at home. I'm running PostgreSQL 7.1.3 and PHP 4.1.1.
--
Jeff Self
City of Newport News
2400 Washington Ave.
Newport News, VA 23607
757-926-6930


Re: Not able to connect to server from PHP

From
timothy_maguire@hartehanks.com
Date:
When I connect I don't like to use the user name attribute.  You might also
want to try the port attribute.

Try something like this:

$conn =pg_connect("host=localhost port=5432 dbname=personnel") or die
("unable to connect to Internal DB");

Tim.

Timothy P. Maguire
Web Developer II
Harte-Hanks
978 436 3325




                      Jeff Self
                      <jself@ci.newport-n        To:       pgsql-php@postgresql.org
                      ews.va.us>                 cc:
                      Sent by:                   Subject:  Not able to connect to server from PHP
                      pgsql-php-owner@pos
                      tgresql.org


                      01/22/2002 03:13 PM






I'm working on a personnel database for my department. I can connect
just fine using 'psql personnel'. I've created a PHP script to get a
list of departments, but I'm getting the following error message:

Warning: Unable to connect to PostgreSQL server: Peer authentication
failed for user 'jeff' in /var/www/personnel/departments.php on line 10
Unable to connect to database.

Here's my script:
<?php
//
// Display Departments
//
// departments.php, v 1.0

include ($DOCUMENT_ROOT.'/personnel/include/functions.inc');

$conn = pg_pconnect("dbname=personnel user=jeff");
if (!$conn) {
 echo "Unable to connect to database.";
 exit;
}

Everything is running locally right now, Apache, PHP, PostgreSQL. I
never modified my pg_hba.conf file. Everything looks identical as my
system at home. I'm running PostgreSQL 7.1.3 and PHP 4.1.1.
--
Jeff Self
City of Newport News
2400 Washington Ave.
Newport News, VA 23607
757-926-6930


---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/users-lounge/docs/faq.html
HARTE- HANKS PRIVILEGED AND CONFIDENTIAL INFORMATION- if you are not the
addressee or authorized to receive this for the addressee, you must not
use, copy, disclose or take any action based on this message or any
information herein and should delete this message.





Re: Not able to connect to server from PHP

From
Jeff Self
Date:
Ok, I tried this and this is the error message I get now:

Warning: Unable to connect to PostgreSQL server: FATAL 1: user
"www-data" does not exist in /var/www/personnel/include/database.inc on
line 9
Could not connect to database.

www-data is the user and group for apache. I don't know what to make of
this.

Here's my database.inc file:

<?php
//
// database.inc
//
// Database Information

    $dbname = "personnel";

    $conn = pg_pconnect("host=localhost port=5432 dbname=$dbname");
    if (!$conn) {
        echo "Could not connect to database.";
        exit;
    }
?>


On Tue, 2002-01-22 at 15:54, timothy_maguire@hartehanks.com wrote:
>
> When I connect I don't like to use the user name attribute.  You might also
> want to try the port attribute.
>
> Try something like this:
>
> $conn =pg_connect("host=localhost port=5432 dbname=personnel") or die
> ("unable to connect to Internal DB");
>
> Tim.
>
> Timothy P. Maguire
> Web Developer II
> Harte-Hanks
> 978 436 3325

--
Jeff Self
Information Technology Analyst
Department of Personnel
City of Newport News
2400 Washington Ave.
Newport News, VA 23607
757-926-6930


Re: Not able to connect to server from PHP

From
timothy_maguire@hartehanks.com
Date:
on my server, I have 'http' registered as a user for my database.  you can
try that.

Or you can add the user=username password=password to the pg_connect()
function.

Tim.

Timothy P. Maguire
Web Developer II
Harte-Hanks
978 436 3325




                      Jeff Self
                      <jself@ci.newport-        To:       timothy_maguire@hartehanks.com
                      news.va.us>               cc:       pgsql-php@postgresql.org
                                                Subject:  Re: Not able to connect to server from PHP
                      01/22/2002 04:18
                      PM






Ok, I tried this and this is the error message I get now:

Warning: Unable to connect to PostgreSQL server: FATAL 1: user
"www-data" does not exist in /var/www/personnel/include/database.inc on
line 9
Could not connect to database.

www-data is the user and group for apache. I don't know what to make of
this.

Here's my database.inc file:

<?php
//
// database.inc
//
// Database Information

 $dbname = "personnel";

 $conn = pg_pconnect("host=localhost port=5432 dbname=$dbname");
 if (!$conn) {
  echo "Could not connect to database.";
  exit;
 }
?>


On Tue, 2002-01-22 at 15:54, timothy_maguire@hartehanks.com wrote:
>
> When I connect I don't like to use the user name attribute.  You might
also
> want to try the port attribute.
>
> Try something like this:
>
> $conn =pg_connect("host=localhost port=5432 dbname=personnel") or die
> ("unable to connect to Internal DB");
>
> Tim.
>
> Timothy P. Maguire
> Web Developer II
> Harte-Hanks
> 978 436 3325

--
Jeff Self
Information Technology Analyst
Department of Personnel
City of Newport News
2400 Washington Ave.
Newport News, VA 23607
757-926-6930

HARTE- HANKS PRIVILEGED AND CONFIDENTIAL INFORMATION- if you are not the
addressee or authorized to receive this for the addressee, you must not
use, copy, disclose or take any action based on this message or any
information herein and should delete this message.





Re: Not able to connect to server from PHP

From
jeff fitzmyers
Date:
I'm not sure, but you might try: CREATE USER www-data;
and then give the user permissions for the table:
GRANT INSERT,SELECT,UPDATE ON "personnel" TO "www-data";

jeff


On Tuesday, January 22, 2002, at 01:18 PM, Jeff Self wrote:

> Ok, I tried this and this is the error message I get now:
>
> Warning: Unable to connect to PostgreSQL server: FATAL 1: user
> "www-data" does not exist in /var/www/personnel/include/database.inc on
> line 9
> Could not connect to database.
>
> www-data is the user and group for apache. I don't know what to make of
> this.
>
> Here's my database.inc file:
>
> <?php
> //
> // database.inc
> //
> // Database Information
>
>     $dbname = "personnel";
>
>     $conn = pg_pconnect("host=localhost port=5432 dbname=$dbname");
>     if (!$conn) {
>         echo "Could not connect to database.";
>         exit;
>     }
> ?>
>
>
> On Tue, 2002-01-22 at 15:54, timothy_maguire@hartehanks.com wrote:
>>
>> When I connect I don't like to use the user name attribute.  You might
>> also
>> want to try the port attribute.
>>
>> Try something like this:
>>
>> $conn =pg_connect("host=localhost port=5432 dbname=personnel") or die
>> ("unable to connect to Internal DB");
>>
>> Tim.
>>
>> Timothy P. Maguire
>> Web Developer II
>> Harte-Hanks
>> 978 436 3325
>
> --
> Jeff Self
> Information Technology Analyst
> Department of Personnel
> City of Newport News
> 2400 Washington Ave.
> Newport News, VA 23607
> 757-926-6930
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org
>


Re: Not able to connect to server from PHP

From
Stephan Borg
Date:
In addition to that, check you pg_hba.conf file for restrictions to
using the db over ip.

Rgds,
Stephan

On Wed, 2002-01-23 at 08:49, jeff fitzmyers wrote:
> I'm not sure, but you might try: CREATE USER www-data;
> and then give the user permissions for the table:
> GRANT INSERT,SELECT,UPDATE ON "personnel" TO "www-data";
>
> jeff
>
>
> On Tuesday, January 22, 2002, at 01:18 PM, Jeff Self wrote:
>
> > Ok, I tried this and this is the error message I get now:
> >
> > Warning: Unable to connect to PostgreSQL server: FATAL 1: user
> > "www-data" does not exist in /var/www/personnel/include/database.inc on
> > line 9
> > Could not connect to database.
> >
> > www-data is the user and group for apache. I don't know what to make of
> > this.
> >
> > Here's my database.inc file:
> >
> > <?php
> > //
> > // database.inc
> > //
> > // Database Information
> >
> >     $dbname = "personnel";
> >
> >     $conn = pg_pconnect("host=localhost port=5432 dbname=$dbname");
> >     if (!$conn) {
> >         echo "Could not connect to database.";
> >         exit;
> >     }
> > ?>
> >
> >
> > On Tue, 2002-01-22 at 15:54, timothy_maguire@hartehanks.com wrote:
> >>
> >> When I connect I don't like to use the user name attribute.  You might
> >> also
> >> want to try the port attribute.
> >>
> >> Try something like this:
> >>
> >> $conn =pg_connect("host=localhost port=5432 dbname=personnel") or die
> >> ("unable to connect to Internal DB");
> >>
> >> Tim.
> >>
> >> Timothy P. Maguire
> >> Web Developer II
> >> Harte-Hanks
> >> 978 436 3325
> >
> > --
> > Jeff Self
> > Information Technology Analyst
> > Department of Personnel
> > City of Newport News
> > 2400 Washington Ave.
> > Newport News, VA 23607
> > 757-926-6930
> >
> >
> > ---------------------------(end of broadcast)---------------------------
> > TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org
> >
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister command
>     (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)
--
ÿþS


Re: Not able to connect to server from PHP

From
Jeff Self
Date:
Thanks for the tips everyone. I figured it out this morning. My
pg_hba.conf file had local set to peer sameuser instead of trust. I
don't know how that happened.

On Tue, 2002-01-22 at 16:11, timothy_maguire@hartehanks.com wrote:
>
> on my server, I have 'http' registered as a user for my database.  you can
> try that.
>
> Or you can add the user=username password=password to the pg_connect()
> function.
>
> Tim.
>
> Timothy P. Maguire
> Web Developer II
> Harte-Hanks
> 978 436 3325
>
>
>
>
>                       Jeff Self
>                       <jself@ci.newport-        To:       timothy_maguire@hartehanks.com
>                       news.va.us>               cc:       pgsql-php@postgresql.org
>                                                 Subject:  Re: Not able to connect to server from PHP
>                       01/22/2002 04:18
>                       PM
>
>
>
>
>
>
> Ok, I tried this and this is the error message I get now:
>
> Warning: Unable to connect to PostgreSQL server: FATAL 1: user
> "www-data" does not exist in /var/www/personnel/include/database.inc on
> line 9
> Could not connect to database.
>
> www-data is the user and group for apache. I don't know what to make of
> this.
>
> Here's my database.inc file:
>
> <?php
> //
> // database.inc
> //
> // Database Information
>
>  $dbname = "personnel";
>
>  $conn = pg_pconnect("host=localhost port=5432 dbname=$dbname");
>  if (!$conn) {
>   echo "Could not connect to database.";
>   exit;
>  }
> ?>
>
>
> On Tue, 2002-01-22 at 15:54, timothy_maguire@hartehanks.com wrote:
> >
> > When I connect I don't like to use the user name attribute.  You might
> also
> > want to try the port attribute.
> >
> > Try something like this:
> >
> > $conn =pg_connect("host=localhost port=5432 dbname=personnel") or die
> > ("unable to connect to Internal DB");
> >
> > Tim.
> >
> > Timothy P. Maguire
> > Web Developer II
> > Harte-Hanks
> > 978 436 3325
>
> --
> Jeff Self
> Information Technology Analyst
> Department of Personnel
> City of Newport News
> 2400 Washington Ave.
> Newport News, VA 23607
> 757-926-6930
>
> HARTE- HANKS PRIVILEGED AND CONFIDENTIAL INFORMATION- if you are not the
> addressee or authorized to receive this for the addressee, you must not
> use, copy, disclose or take any action based on this message or any
> information herein and should delete this message.
>
>
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/users-lounge/docs/faq.html
--
Jeff Self
Information Technology Analyst
Department of Personnel
City of Newport News
2400 Washington Ave.
Newport News, VA 23607
757-926-6930


Re: Not able to connect to server from PHP

From
Chadwick Rolfs
Date:
I had the same problem, and found identd to be sending encrypted usernames
for authentication.  If you're fine with trust (those of us with paranoid
settings are never fine with trust), cool.  If you don't want to use
trust, try passwd, or something else.  I think the original problem is the
identd sending encrypted usernames...man identd.
Maybe php can encrypt your username the same way?  That way you don't have
to trust anyone:)

On 22 Jan 2002, Jeff Self wrote:

> I'm working on a personnel database for my department. I can connect
> just fine using 'psql personnel'. I've created a PHP script to get a
> list of departments, but I'm getting the following error message:
>
> Warning: Unable to connect to PostgreSQL server: Peer authentication
> failed for user 'jeff' in /var/www/personnel/departments.php on line 10
> Unable to connect to database.
>
> Here's my script:
> <?php
> //
> // Display Departments
> //
> // departments.php, v 1.0
>
> include ($DOCUMENT_ROOT.'/personnel/include/functions.inc');
>
> $conn = pg_pconnect("dbname=personnel user=jeff");
> if (!$conn) {
>     echo "Unable to connect to database.";
>     exit;
> }
>
> Everything is running locally right now, Apache, PHP, PostgreSQL. I
> never modified my pg_hba.conf file. Everything looks identical as my
> system at home. I'm running PostgreSQL 7.1.3 and PHP 4.1.1.
> --
> Jeff Self
> City of Newport News
> 2400 Washington Ave.
> Newport News, VA 23607
> 757-926-6930
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/users-lounge/docs/faq.html
>

Chadwick Rolfs - cmr@gis.net
Cleveland State University - Student
Music Major - The Holden Arboretum Volunteer
Computer Programmer - Student Employee
--*I finally found powdered water;
I just can't figure out what to add to it*--