Skip to content

Instantly share code, notes, and snippets.

@tigusigalpa
Last active March 11, 2024 17:43
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save tigusigalpa/2d1ec6e258ed96221abf9679622d274a to your computer and use it in GitHub Desktop.
Save tigusigalpa/2d1ec6e258ed96221abf9679622d274a 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