pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: rob stone <floriparob@gmail.com>
To: Howard Wells <mr284@protonmail.com>
To: pgsql-general@postgresql.org <pgsql-general@postgresql.org>
Subject: Re: How to access Postgres .pgpass file from php?
Date: Sun, 08 Sep 2019 22:02:00 +1000
Message-ID: <c2eebcb1d37ac6456570f64ade62e98add1cde22.camel@gmail.com> (raw)
In-Reply-To: <7ZvCVAa3C3yXdOHkX2YApxOPAGV0ueZfXcWSrK57nZvSbfCbUlQJB5LUt1qH5Y2lu-VWqHwETGk4fwCFtecnSz4OQb9gY_hIyxi4Vwa6LKw=@protonmail.com>
References: <7ZvCVAa3C3yXdOHkX2YApxOPAGV0ueZfXcWSrK57nZvSbfCbUlQJB5LUt1qH5Y2lu-VWqHwETGk4fwCFtecnSz4OQb9gY_hIyxi4Vwa6LKw=@protonmail.com>

Hello Howard,

On Sat, 2019-09-07 at 22:17 +0000, Howard Wells wrote:
> I have my php files in the web root, and the Postgres 10 logon
> credentials are in the php file.  I want to put them outside the web
> root for security, because a malicious robot could easily read the
> credentials. 
> 
> After research, I found the .pgpass file.  That looks like the ideal
> solution, but after even more research, I haven't found how to use
> that file from a php logon script. 
> 
> Here is the section from my php script:
> 
> $dsn =
> vsprintf('pgsql:host=%s;port=%s;dbname=%s;user=%s;password=%s', [
>     'host' => '000.00.00.00',
>     'port' => '5432',
>     'dbname' => '[dbname]',
>     'user' => '[username]',
>     'password' => '[password]',
> ]);
> 
> Currently I store the real dbname, user and password in the php.  My
> questions are:
> 
> 1.	How can I access it from the .pgpass file instead? 
> 
> 2.	Where is .phpass loccated in Apache2 Ubuntu 18.04?
> 
> Thanks for any help with this. 
> 
> Howard
> 
> 
> 

We use pg_service.conf to hold the access credentials.
It's just pg_connect("service=sandbox") for example, where 'sandbox' is
the tag for the database you wish to access.
Using Debian it is kept in the /etc/php/7.3/apache2 path, where 7.3
represents the php version. It needs to be owned by the Apache user
which defaults to 'www-data'. Permissions are 0600.

HTH,
Robert








view thread (3+ messages)

Message-ID: <c2eebcb1d37ac6456570f64ade62e98add1cde22.camel@gmail.com>
Permalink:  ../c2eebcb1d37ac6456570f64ade62e98add1cde22.camel@gmail.com/
Also on:    postgresql.org/message-id/c2eebcb1d37ac6456570f64ade62e98add1cde22.camel@gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: floriparob@gmail.com, mr284@protonmail.com
  Subject: Re: How to access Postgres .pgpass file from php?
  In-Reply-To: <c2eebcb1d37ac6456570f64ade62e98add1cde22.camel@gmail.com>
  References: <7ZvCVAa3C3yXdOHkX2YApxOPAGV0ueZfXcWSrK57nZvSbfCbUlQJB5LUt1qH5Y2lu-VWqHwETGk4fwCFtecnSz4OQb9gY_hIyxi4Vwa6LKw=@protonmail.com> <c2eebcb1d37ac6456570f64ade62e98add1cde22.camel@gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox