Skip to content
Advertisement

Connecting to PGSQL over SSL via Red Bean PHP

$dbh = new PDO('pgsql:localhost=host;port=26257;dbname=bank;sslmode=require;sslcert=[path]/client.maxroach.crt;sslkey=[path]/client.maxroach.key;sslrootcert=[path]/ca.crt;',
    'maxroach', null, array(
      PDO::ATTR_ERRMODE          => PDO::ERRMODE_EXCEPTION,
      PDO::ATTR_EMULATE_PREPARES => true,
  ));

This a pdo method, i need configure red bean connection for ssl pgsql connection

R::setup( "pgsql:host=$ip;port=$port;dbname=$dbname",$user, $password, $frozen ); ?

Advertisement

Answer

You definitely need to write the full path to certificates and keys, otherwise nothing will work.

$crt = $_SERVER["DOCUMENT_ROOT"]."/client.crt";

$key = $_SERVER["DOCUMENT_ROOT"]."/client.key";

$ca = $_SERVER["DOCUMENT_ROOT"]."/ca.crt";

R::setup( "pgsql:host=$ip;port=$port;dbname=$dbname;sslmode=verify-ca;sslcert=$crt;sslkey=$key;sslrootcert=$ca;",$user, $password, $frozen );

sslmode=verify-ca; better use sslmode=verify-full

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement