note 43055 deleted from function.pg-connect by bjori

From: Date: Tue, 12 Dec 2006 08:52:06 +0000
Subject: note 43055 deleted from function.pg-connect by bjori
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-120535@lists.php.net to get a copy of this message
Note Submitter: grheatley at uclan dot ac dot uk ---- 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

« previous php.notes (#120535) next »