From: | "John Coulthard" <bahhab(at)hotmail(dot)com> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Unable to connect to PostgreSQL server via PHP |
Date: | 2007-08-15 09:55:45 |
Message-ID: | BAY121-F21350AF1A219157C6CB9A8CFDE0@phx.gbl |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
It was SELinux denying apache permission to make TCP connections!
I thought I had SELinux turned off but it wasn't. To be sure it is do
/usr/sbin/sestatus | grep SELinux
and if it comes back with anything other than SELinux status: disabled it's
still running.
While I was talking to the php board I discovered you can configure php to
run from the command line (mine was by default). So I wrote this bit of php
(obviously change the database name and you may need a user and passwd)...
<?php
$dbconn=pg_connect("dbname=lumbribase");
if ( ! $dbconn ) {
echo "Error connecting to the database !<br> " ;
printf("%s", pg_errormessage( $dbconn ) );
exit(); }
else {echo "connected", "\n";}
?>
....saved it as test.php and at a shell prompt ran...
[john@ tmp]$ php test.php
connected
If you get 'connected' you know php and postgres are talking via tcp and
some secondary process (firewall/SELinux) is preventing the apache
connection.
Thanks for the help.
>From: "John Coulthard" <bahhab(at)hotmail(dot)com>
>To: tgl(at)sss(dot)pgh(dot)pa(dot)us
>CC: pgsql-general(at)postgresql(dot)org
>Subject: Re: [GENERAL] Unable to connect to PostgreSQL server via PHP
>Date: Mon, 13 Aug 2007 15:34:19 +0000
>
>
>
>
>>From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
>>To: "John Coulthard" <bahhab(at)hotmail(dot)com>
>>CC: pgsql-general(at)postgresql(dot)org
>>Subject: Re: [GENERAL] Unable to connect to PostgreSQL server via PHP
>>Date: Mon, 13 Aug 2007 10:09:15 -0400
>>
>>"John Coulthard" <bahhab(at)hotmail(dot)com> writes:
>> > That's not my problem though this is "could not connect to server:
>> > Permission denied" If it's denying permission I must have the
>>permissions
>> > set wrong but where to I start looking for them?
>>
>>"Permission denied" is a pretty strange error for a TCP connect failure,
>>as that is not a filesystem operation.
>>
>>Are you able to connect with psql, or some other non-php client?
>>Use "psql -h localhost" to make sure it tries a TCP connection not
>>a Unix-socket connection.
>>
>
>Thanks. You mean like this? This connects without an error.
>
>[root(at)xyala john]# su webuser
>[webuser(at)xyala john]$ psql -h localhost lumbribase
>Welcome to psql 8.0.8, 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
>
>lumbribase=>
>
>_________________________________________________________________
>FREE pop-up blocking with the new MSN Toolbar - get it now!
>http://toolbar.msn.click-url.com/go/onm00200415ave/direct/01/
>
>
>---------------------------(end of broadcast)---------------------------
>TIP 5: don't forget to increase your free space map settings
_________________________________________________________________
Don't just search. Find. Check out the new MSN Search!
http://search.msn.click-url.com/go/onm00200636ave/direct/01/
From | Date | Subject | |
---|---|---|---|
Next Message | Pavel Stehule | 2007-08-15 09:57:50 | is this trigger safe and efective? - locking (caching via triiggers) |
Previous Message | Alexander Staubo | 2007-08-15 09:32:23 | Re: Transactional DDL |