Skip to content

Instantly share code, notes, and snippets.

@etenzy
Forked from tigusigalpa/database.php
Created May 13, 2020 21:56
Show Gist options
  • Select an option

  • Save etenzy/b62baad6f0f283e3509ff16c2b43b7f7 to your computer and use it in GitHub Desktop.

Select an option

Save etenzy/b62baad6f0f283e3509ff16c2b43b7f7 to your computer and use it in GitHub Desktop.
Laravel PostgreSQL SSL encryption connection config
<?php
/**
* 1. You have to store your client SSL certificates on your Laravel server, in my case this is /var/certs/mydomain.com/...
* 2. You have to right select SSL mode for PostgreSQL (see https://www.postgresql.org/docs/current/libpq-ssl.html#LIBPQ-SSL-SSLMODE-STATEMENTS), verify-full means your server CA is signed for real domain name for the PostgreSQL server (recommended)
* 3. Go to Laravel config/database.php to the section 'pgsql' and extend it to the following:
*/
return [
/*...*/
'connections' => [
/*'mysql' etc*/
'pgsql' => [
/*driver, host, database, username etc*/
'sslmode' => 'verify-ca', //depends on your security level https://www.postgresql.org/docs/current/libpq-ssl.html#LIBPQ-SSL-SSLMODE-STATEMENTS
'options' => [
'sslrootcert' => '/var/certs/mysite.com/postgresql-root.crt',
'sslcert' => '/var/certs/mysite.com/postgresql-client.crt',
'sslkey' => '/var/certs/mysite.com/postgresql-client.key',
]
]
]
];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment