note 43055 added to function.pg-connect
| From: | grheatley at uclan dot ac dot uk | Date: | Tue, 08 Jun 2004 11:19:30 +0000 |
| Subject: | note 43055 added to function.pg-connect | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-70716@lists.php.net to get a copy of this message | ||
This is a quick note about getting postreSQL permissions to work for a Debian / php / PostgreSQL /
Apache combination all *running on the same localhost*, so you can use unix sockets and not a TCP/IP
connection.
Lets say you have a PostgreSQL user called 'fred' who has ownership of a database called
'freds_db'. To allow apache to connect to freds_db do this:
1) Set up a PostgreSQL password for user fred:
ALTER USER fred WITH PASSWORD 'freds_pass';
2) As root, edit /etc/postgresql/pg_hba.conf, adding the line (in lower case, below):
TYPE DATABASE USER IP-ADDRESS IP-MASK METHOD
local freds_db fred md5
3) As root, restart PostgreSQL:
/etc/init.d/postgresql restart
4) In php you should be able then to use:
<?php
pg_connect("dbname=freds_db user=fred password=freds_pass") or die("Couldn't
Connect ".pg_last_error());
?>
A side effect of this is that fred now has to supply his password when he connects to freds_db in
PostgreSQL via the command line, and any Debian user can connect to freds_db as fred if they know
his password.
I'm not sure if this is the optimally secure method of achieving the desired result, but it
works.
Cheers!
--
Guy
----
Manual Page -- http://www.php.net/manual/en/function.pg-connect.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+43055
Delete -- http://master.php.net/manage/user-notes.php?action=delete+43055&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+43055&report=yes
Search -- http://master.php.net/manage/user-notes.php