Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i6wpN-00039z-Ri for pgsql-general@arkaria.postgresql.org; Sun, 08 Sep 2019 13:02:02 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1i6wpL-0003mM-SA for pgsql-general@arkaria.postgresql.org; Sun, 08 Sep 2019 13:01:59 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i6wpL-0003jF-Fz for pgsql-general@lists.postgresql.org; Sun, 08 Sep 2019 13:01:59 +0000 Received: from mail-pg1-x543.google.com ([2607:f8b0:4864:20::543]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i6wpH-0005VX-Vc for pgsql-general@postgresql.org; Sun, 08 Sep 2019 13:01:58 +0000 Received: by mail-pg1-x543.google.com with SMTP id u72so6170505pgb.10 for ; Sun, 08 Sep 2019 06:01:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:subject:from:to:date:in-reply-to:references:user-agent :mime-version:content-transfer-encoding; bh=BHResX6eugIdQdX7+CMz14Yf0Z+0Q+KDsFXqQCT2oN4=; b=W6FOMOVfyE0la8x/hQvzr45w6R8jjGmmK0SCzTkb5VZ8v2eSUzFMSr21tPTBjjrwqF B4mqgQlJAlGZATPxMnGxHgi/1YTN82J2otSJPc1g3QomwY9dlclfT3msrAz/75x0ulSM 9JXP0GtHNP3PxXHP0KR/vE6le4cTkQFIIWV8KnAChKQ+rr7xXxYJcDcN9cTsILh6iIws /uj/y0s49YI+MhB5H/l77JMru2EuLrvoCdKTiD5WiAKepjij93C7OMxDZ+VJcroJVP2M khxXpXZvHsMMc6e7LmWNMTDTTL+A7Jh6mndWL5ZRDt27IprR7rKZiTEgNTc2O3hflMFu tbLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:subject:from:to:date:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=BHResX6eugIdQdX7+CMz14Yf0Z+0Q+KDsFXqQCT2oN4=; b=LIfK9vXWbnn+mv4JN9RTF90r+laywkjeEQg0IGpwckLypdaWFvS8WZC86uYlC4u9US s/vWCB8iXGPzqSF7pe4wr2prQYaCMWrgQbwlrIGAEk4USifHxJcKVYrMox6QAebUUS4U NJdoKyPSJ2Tuswrw4fvYkyf6M17Coa8ywUjkZlkH85DKIn6PEHNDDZG0EoRbG43DBMdi t3kmcdx7qzFam/CVeB9yHaUEzY4AiEW9j3UyLf5XPlgU5A1iouMkyS1x0hukzxQUVSkC UqrW9ejOwvMFF0FjyNsYXpsyxkb8E87Kf74WKf6Hwj73OaQxEK9b2x6XdNu2GmWQz6EZ K46A== X-Gm-Message-State: APjAAAUmsleHnC2Z/OU8tQeWOoFk/2msHYhY0scpCY6cmWGuRqQcRryQ ExooB78eb1KiZohtLlIE5IiOowyp X-Google-Smtp-Source: APXvYqwbn9tl8dc+F71vkmp3gND1iMrgYmKnrLxfqcj+A8ClE/deMsq1lui1hz5J7WF0CezNx0crXQ== X-Received: by 2002:a63:5f95:: with SMTP id t143mr16623275pgb.304.1567944125251; Sun, 08 Sep 2019 05:02:05 -0700 (PDT) Received: from 192-168-1-100.tpgi.com.au ([61.68.249.254]) by smtp.gmail.com with ESMTPSA id l3sm10955311pjq.18.2019.09.08.05.02.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Sep 2019 05:02:04 -0700 (PDT) Message-ID: Subject: Re: How to access Postgres .pgpass file from php? From: rob stone To: Howard Wells , "pgsql-general@postgresql.org" Date: Sun, 08 Sep 2019 22:02:00 +1000 In-Reply-To: <7ZvCVAa3C3yXdOHkX2YApxOPAGV0ueZfXcWSrK57nZvSbfCbUlQJB5LUt1qH5Y2lu-VWqHwETGk4fwCFtecnSz4OQb9gY_hIyxi4Vwa6LKw=@protonmail.com> References: <7ZvCVAa3C3yXdOHkX2YApxOPAGV0ueZfXcWSrK57nZvSbfCbUlQJB5LUt1qH5Y2lu-VWqHwETGk4fwCFtecnSz4OQb9gY_hIyxi4Vwa6LKw=@protonmail.com> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.30.5-1.1 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 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