pg.ddx.io pgsql-general@postgresql.org mailing list archive
help / color / mirror / Atom feedHow to access Postgres .pgpass file from php?
3+ messages / 3 participants
[nested] [flat]
* How to access Postgres .pgpass file from php?
@ 2019-09-07 22:17 Howard Wells <mr284@protonmail.com>
0 siblings, 2 replies; 3+ messages in thread
From: Howard Wells @ 2019-09-07 22:17 UTC (permalink / raw)
To: pgsql-general
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
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: How to access Postgres .pgpass file from php?
@ 2019-09-07 22:40 Adrian Klaver <adrian.klaver@aklaver.com>
parent: Howard Wells <mr284@protonmail.com>
1 sibling, 0 replies; 3+ messages in thread
From: Adrian Klaver @ 2019-09-07 22:40 UTC (permalink / raw)
To: Howard Wells <mr284@protonmail.com>; pgsql-general
On 9/7/19 3:17 PM, 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?
I think what you are looking for is the connection service file:
https://www.postgresql.org/docs/11/libpq-pgservice.html
>
> 2. Where is .phpass loccated in Apache2 Ubuntu 18.04?
Information on where .pgpass can be:
https://www.postgresql.org/docs/11/libpq-pgpass.html
>
> Thanks for any help with this.
>
> Howard
>
>
>
--
Adrian Klaver
adrian.klaver@aklaver.com
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: How to access Postgres .pgpass file from php?
@ 2019-09-08 12:02 rob stone <floriparob@gmail.com>
parent: Howard Wells <mr284@protonmail.com>
1 sibling, 0 replies; 3+ messages in thread
From: rob stone @ 2019-09-08 12:02 UTC (permalink / raw)
To: Howard Wells <mr284@protonmail.com>; pgsql-general
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
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2019-09-08 12:02 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2019-09-07 22:17 How to access Postgres .pgpass file from php? Howard Wells <mr284@protonmail.com>
2019-09-07 22:40 ` Adrian Klaver <adrian.klaver@aklaver.com>
2019-09-08 12:02 ` rob stone <floriparob@gmail.com>
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