Configuring Drupal 9+
Step 1: Ensure you have skpr/config as a Composer dependency.
composer require skpr/config=^3.0
Step 2: Load config from disk at the top of settings.php
:
use Skpr\SkprConfig;
$skpr = SkprConfig::create()->load();
Step 3: Set your database credentials in the project settings.php
file:
$databases['default']['default'] = [
'driver' => 'mysql',
'database' => $skpr->get('mysql.default.database') ?: 'local',
'username' => $skpr->get('mysql.default.username') ?: 'local',
'password' => $skpr->get('mysql.default.password') ?: 'local',
'host' => $skpr->get('mysql.default.hostname') ?: '127.0.0.1',
];
if ($cert_path = $skpr->get('mysql.default.ca.crt')) {
$databases['default']['default']['pdo'][PDO::MYSQL_ATTR_SSL_CA] = $cert_path;
}
Step 4: Set up file paths in settings.php
:
$settings['file_public_path'] = 'sites/default/files';
$settings['file_temp_path'] = $skpr->get('mount.temporary') ?: '/tmp';
$settings['file_private_path'] = $skpr->get('mount.private') ?: 'sites/default/files/private';
$settings['php_storage']['twig'] = [
'directory' => ($skpr->get('mount.local') ?: DRUPAL_ROOT . '/..') . '/.php',
];
Step 5: Set up trusted host patterns in settings.php
:
$settings['trusted_host_patterns'][] = '^127\.0\.0\.1$';
foreach ($skpr->hostNames() as $hostname) {
$settings['trusted_host_patterns'][] = '^' . preg_quote($hostname) . '$';
}
Step 6: Set up reverse proxy addresses in settings.php
:
if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$settings['reverse_proxy'] = TRUE;
$settings['reverse_proxy_proto_header'] = 'HTTP_CLOUDFRONT_FORWARDED_PROTO';
$settings['reverse_proxy_port_header'] = 'SERVER_PORT';
$settings['reverse_proxy_addresses'] = $skpr->ipRanges();
}
Step 7: Set up drush aliases:
Drush configuration can be setup per Skpr environment. This is useful for things like the Drush URI.
In drush/drush.yml
, register configuration files per Skpr environment, and one for local environments if necessary:
drush:
paths:
config:
- /data/drush/local.yml
- /data/drush/skpr/${env.SKPR_ENV}.yml
Then for each environment create a file under drush/skpr/ENV.yml where ENV is the name of the environment.
For example, to set the Drush URI for the prod
environment, add drush/skpr/prod.yml
options:
uri: 'https://prod.example.test.skpr.live/'