Thread: PHP cann't access to postgres databse
Hi gurus! my PHP scripts don't call upon the postgres database from within HTML files served to web browsers by Apache, but PHP scritps itself can access to database. I guess some configuration between PHP and Apache is wrong. Do anybody have any idea? Thanks! Dong He
On Thu, Jun 25, 2009 at 6:54 PM, <donghe@caltech.edu> wrote: > Hi gurus! > > my PHP scripts don't call upon the postgres database from within HTML > files served to web browsers by Apache, but PHP scritps itself can access > to database. I guess some configuration between PHP and Apache is wrong. > Do anybody have any idea? > Thanks! Yeah, you're looking for pg_hba.conf and postgresql.conf.
Yes, I did configured these two files, so, PHP can talk with postgres, but Apache-owned PHP can not. > On Thu, Jun 25, 2009 at 6:54 PM, <donghe@caltech.edu> wrote: >> Hi gurus! >> >> my PHP scripts don't call upon the postgres database from within HTML >> files served to web browsers by Apache, but PHP scritps itself can >> access >> to database. I guess some configuration between PHP and Apache is wrong. >> Do anybody have any idea? >> Thanks! > > Yeah, you're looking for pg_hba.conf and postgresql.conf. > > -- > Sent via pgsql-admin mailing list (pgsql-admin@postgresql.org) > To make changes to your subscription: > http://www.postgresql.org/mailpref/pgsql-admin >
Some linux distros (debian, for example) have two php.ini files, one for php scripts and a second one for Apache2 config.
Perhaps you have lost one of these files...
I assume you have installed mod-php for Apache.
-----Original Message-----
From: donghe@caltech.edu
To: pgsql-admin@postgresql.org
Subject: [ADMIN] PHP cann't access to postgres databse
Date: Thu, 25 Jun 2009 17:54:43 -0700 (PDT)
Perhaps you have lost one of these files...
I assume you have installed mod-php for Apache.
-----Original Message-----
From: donghe@caltech.edu
To: pgsql-admin@postgresql.org
Subject: [ADMIN] PHP cann't access to postgres databse
Date: Thu, 25 Jun 2009 17:54:43 -0700 (PDT)
Hi gurus! my PHP scripts don't call upon the postgres database from within HTML files served to web browsers by Apache, but PHP scritps itself can access to database. I guess some configuration between PHP and Apache is wrong. Do anybody have any idea? Thanks! Dong He
the error message in Apache error-log is " PHP Warning: pg_connect() [<a href='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 "localhost" and accepting\n\tTCP/IP connections on port 5432? " > > It will be good to know what the error messages are, so we can go from > there > > >> Date: Thu, 25 Jun 2009 17:54:43 -0700 >> Subject: [ADMIN] PHP cann't access to postgres databse >> From: donghe@caltech.edu >> To: pgsql-admin@postgresql.org >> >> Hi gurus! >> >> my PHP scripts don't call upon the postgres database from within HTML >> files served to web browsers by Apache, but PHP scritps itself can >> access >> to database. I guess some configuration between PHP and Apache is wrong. >> Do anybody have any idea? >> Thanks! >> >> Dong He >> >> >> >> >> >> -- >> Sent via pgsql-admin mailing list (pgsql-admin@postgresql.org) >> To make changes to your subscription: >> http://www.postgresql.org/mailpref/pgsql-admin >
<donghe@caltech.edu> wrote: > Is the server running on host "localhost" > and accepting TCP/IP connections on port 5432? Is it? Depending on your platform, you can check which ports are accepting connections with something like: netstat -plnt If you don't see your port open there, listening on all addresses or on the localhost IP, you probably need to modify your postgresql.conf file to set listen_addresses or port as you need them. (You will need to restart PostgreSQL.) If the postgresql.conf file is good, you must have something misconfigured in the networking on that box. You could run: ping localhost to see what that gives you. -Kevin
Because the error is "Permission denied", I'm guessing it's permissions on the /tmp/.s.PGSQL.5432 socket that will need checking? The OP's PHP script when run standalone is probably running as root. donghe@caltech.edu wrote: > the error message in Apache error-log is " PHP Warning: pg_connect() [<a > href='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 "localhost" and accepting\n\tTCP/IP > connections on port 5432? " > >
Andy Shellam <andy-lists@networkmail.eu> wrote: > donghe@caltech.edu wrote: >> Unable to connect to PostgreSQL server: >> could not connect to server: Permission denied >> Is the server running on host "localhost" and accepting >> TCP/IP connections on port 5432? " > Because the error is "Permission denied", I'm guessing it's > permissions on the /tmp/.s.PGSQL.5432 socket that will need > checking? If it was trying to get that sort of connection, rather than TCP/IP, the message would be different. Something like: # could not connect to server: No such file or directory # Is the server running locally and accepting # connections on Unix domain socket "/tmp/.s.PGSQL.5432"? You do have a point on the "Permission denied", though. If the problem was where I was suggesting, it would probably say "Connection refused". Perhaps some OS security restriction is in play here. -Kevin
the default port 5432 is associated with postgres and localhost is connected # netstat -plunta | grep 5432 tcp 0 0 127.0.0.1:5432 0.0.0.0:* LISTEN 3962/postgres tcp 0 0 ::1:5432 :::* LISTEN 3962/postgres # ping localhost PING localhost (127.0.0.1) 56(84) bytes of data. 64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.037 ms 64 bytes from localhost (127.0.0.1): icmp_seq=2 ttl=64 time=0.018 ms 64 bytes from localhost (127.0.0.1): icmp_seq=3 ttl=64 time=0.020 ms 64 bytes from localhost (127.0.0.1): icmp_seq=4 ttl=64 time=0.017 ms 64 bytes from localhost (127.0.0.1): icmp_seq=5 ttl=64 time=0.017 ms Dong > <donghe@caltech.edu> wrote: > >> Is the server running on host "localhost" >> and accepting TCP/IP connections on port 5432? > > Is it? > > Depending on your platform, you can check which ports are accepting > connections with something like: > > netstat -plnt > > If you don't see your port open there, listening on all addresses or > on the localhost IP, you probably need to modify your postgresql.conf > file to set listen_addresses or port as you need them. (You will need > to restart PostgreSQL.) > > If the postgresql.conf file is good, you must have something > misconfigured in the networking on that box. You could run: > > ping localhost > > to see what that gives you. > > -Kevin > > -- > Sent via pgsql-admin mailing list (pgsql-admin@postgresql.org) > To make changes to your subscription: > http://www.postgresql.org/mailpref/pgsql-admin >
I think that permissions on the parent directories can result in this error. Carol On Jun 26, 2009, at 1:07 PM, Kevin Grittner wrote: > Andy Shellam <andy-lists@networkmail.eu> wrote: > >> donghe@caltech.edu wrote: >>> Unable to connect to PostgreSQL server: >>> could not connect to server: Permission denied >>> Is the server running on host "localhost" and accepting >>> TCP/IP connections on port 5432? " > >> Because the error is "Permission denied", I'm guessing it's >> permissions on the /tmp/.s.PGSQL.5432 socket that will need >> checking? > > If it was trying to get that sort of connection, rather than TCP/IP, > the message would be different. Something like: > > # could not connect to server: No such file or directory > # Is the server running locally and accepting > # connections on Unix domain socket "/tmp/.s.PGSQL.5432"? > > You do have a point on the "Permission denied", though. If the > problem was where I was suggesting, it would probably say "Connection > refused". Perhaps some OS security restriction is in play here. > > -Kevin > > -- > Sent via pgsql-admin mailing list (pgsql-admin@postgresql.org) > To make changes to your subscription: > http://www.postgresql.org/mailpref/pgsql-admin
> If it was trying to get that sort of connection, rather than TCP/IP, > the message would be different. Something like: > > # could not connect to server: No such file or directory > # Is the server running locally and accepting > # connections on Unix domain socket "/tmp/.s.PGSQL.5432"? > Ah yeah, good point. > > You do have a point on the "Permission denied", though. If the > problem was where I was suggesting, it would probably say "Connection > refused". Perhaps some OS security restriction is in play here. > SELinux? I've never used it personally but have heard it can throw some errors you don't normally expect.
i use fedora 11 > >> If it was trying to get that sort of connection, rather than TCP/IP, >> the message would be different. Something like: >> >> # could not connect to server: No such file or directory >> # Is the server running locally and accepting >> # connections on Unix domain socket "/tmp/.s.PGSQL.5432"? >> > > Ah yeah, good point. >> >> You do have a point on the "Permission denied", though. If the >> problem was where I was suggesting, it would probably say "Connection >> refused". Perhaps some OS security restriction is in play here. >> > > SELinux? I've never used it personally but have heard it can throw some > errors you don't normally expect. > > -- > Sent via pgsql-admin mailing list (pgsql-admin@postgresql.org) > To make changes to your subscription: > http://www.postgresql.org/mailpref/pgsql-admin >
What does your connect string for each look like (with passwords bleeped out)?
I can run this php script from commandline and psql remote access works > What does your connect string for each look like (with passwords bleeped > out)? > > -- > Sent via pgsql-admin mailing list (pgsql-admin@postgresql.org) > To make changes to your subscription: > http://www.postgresql.org/mailpref/pgsql-admin >
Way not to answer the question. On Fri, Jun 26, 2009 at 12:18 PM, <donghe@caltech.edu> wrote: > I can run this php script from commandline and psql remote access works > >> What does your connect string for each look like (with passwords bleeped >> out)? >> >> -- >> Sent via pgsql-admin mailing list (pgsql-admin@postgresql.org) >> To make changes to your subscription: >> http://www.postgresql.org/mailpref/pgsql-admin >> > > > -- When fascism comes to America, it will be intolerance sold as diversity.
donghe@caltech.edu writes: >>> You do have a point on the "Permission denied", though. If the >>> problem was where I was suggesting, it would probably say "Connection >>> refused". Perhaps some OS security restriction is in play here. >> SELinux? I've never used it personally but have heard it can throw some >> errors you don't normally expect. > i use fedora 11 Then it's SELinux. If it works after "setenforce permissive", it's definitely selinux. File a bug against selinux-policy. regards, tom lane
Yes, the issue is from SELinux. thank everybody for help > donghe@caltech.edu writes: >>>> You do have a point on the "Permission denied", though. If the >>>> problem was where I was suggesting, it would probably say "Connection >>>> refused". Perhaps some OS security restriction is in play here. > >>> SELinux? I've never used it personally but have heard it can throw >>> some >>> errors you don't normally expect. > >> i use fedora 11 > > Then it's SELinux. If it works after "setenforce permissive", it's > definitely selinux. File a bug against selinux-policy. > > regards, tom lane >