Skip to content

Instantly share code, notes, and snippets.

@herbdool
Created November 18, 2021 18:24
Show Gist options
  • Save herbdool/4acdbf2b8d8ace2a24f810d52564dc33 to your computer and use it in GitHub Desktop.
Save herbdool/4acdbf2b8d8ace2a24f810d52564dc33 to your computer and use it in GitHub Desktop.
CiviCRM settings file for Drupal 9 on Pantheon
<?php
/**
* CiviCRM Configuration File.
*/
/**
* Installing CiviCRM with Drupal 9 on Pantheon.
*
* 1. Create a new site on Pantheon using Drupal 9 (sftp mode).
* 2. Download the git repository.
* 3. Follow the CiviCRM install instructions https://docs.civicrm.org/installation/en/latest/drupal8/ with Composer.
* 4. Commit the updated composer files and push to Pantheon (ensure it's in git mode).
* 5. Change back to sftp mode.
* 5. Go to Drupal 9 module page and install CiviCRM by enabling.
* 6. This will create a civicrm.settings.php file.
* 7. Download this file via sftp.
* 8. The only thing to keep from this are the keys that are generated: CIVICRM_SITE_KEY, CIVICRM_CRED_KEYS,
* CIVICRM_SIGN_KEYS. Copy them into a separate document.
* 9. Remove all database credentials, keys from civicrm.settings.php. And delete $civicrm_root.
* 10. Save this file (civicrm.settings.local.php) in the same folder as civicrm.settings.php.
* 11. Place this snippet in civicrm.settings.php, just below "global $civicrm_root, $civicrm_setting, $civicrm_paths;"
*
* if (file_exists(__DIR__ . '/civicrm.settings.local.php')) {
* include __DIR__ . '/civicrm.settings.local.php';
* }
*
* 12. Since there should be no database credentials in the db, it should be fine to commit the files to the git repo.
* Alternatively the local settings file could be put outside the webroot.
*/
/**
* Pantheon:
* Populate needed variables based on the Pantheon environment.
*/
if (!empty($_ENV['PANTHEON_SITE'])) {
$pantheon_home = $_ENV['HOME'] . ($_ENV['HOME'] !== '/' ? '/' : '');
// Database Username and Password
$pantheon_db = 'mysql://' . $_ENV['DB_USER'] . ':' . $_ENV['DB_PASSWORD'] . '@';
// Host
$pantheon_db .= $_ENV['DB_HOST'] . ':' . $_ENV['DB_PORT'];
// Database
$pantheon_db .= '/' . $_ENV['DB_NAME'] . '?new_link=true';
}
/**
* CMS
*/
define('CIVICRM_UF', 'Drupal8');
/**
* Databases
*/
if (isset($_ENV['PANTHEON_SITE'])) {
define('CIVICRM_UF_DSN', $pantheon_db);
}
if (isset($_ENV['PANTHEON_SITE'])) {
define('CIVICRM_DSN', $pantheon_db);
}
/**
* Site key
*/
define( 'CIVICRM_SITE_KEY', '6HSYPSUZ9Tq63WQ5nF6cOFrTfyTnPmcjvgFIdKwmGR4');
/**
* Credential keys
*/
define('CIVICRM_CRED_KEYS', 'aes-cbc:hkdf-sha256:dgPp064eVpONanUhKmsAVD7yHfCyNSdSfcDPT8ZGCFs7hieSw');
/**
* Signing keys
*/
define( 'CIVICRM_SIGN_KEYS', 'jwt-hs256:hkdf-sha256:MFwpyNk5MaUzl9K8mN3anI320FOhkRAANOOJnteVZK79uLeVHCmQ');
/**
* File paths and URLs
*/
if (isset($_ENV['PANTHEON_SITE'])) {
$civicrm_root = $pantheon_home . 'code/vendor/civicrm/civicrm-core/';
}
if (isset($_ENV['PANTHEON_SITE'])) {
define('CIVICRM_TEMPLATE_COMPILEDIR', $pantheon_home . 'tmp/civicrm/templates_c/');
}
/**
* URL settings
*/
// Detect if is Pantheon server
if (!empty($_SERVER['HTTP_X_FORWARDED_PROTO'])) {
define('CIVICRM_UF_BASEURL', $_SERVER['HTTP_X_FORWARDED_PROTO'] . '://' . $_SERVER['HTTP_X_FORWARDED_HOST'] . '/');
} else {
define('CIVICRM_UF_BASEURL', $_SERVER['HTTP_X_PROTO'] . $_SERVER['HTTP_HOST'] . '/');
}
/**
* Provide a default public and private CiviCRM file path on Pantheon.
*
* Set [civicrm.files] and [civicrm.private] since Pantheon provides a files/private
* directory instead of using Apache to set permissions on directories.
*/
if (isset($_ENV['PANTHEON_SITE'])) {
$civicrm_paths['civicrm.files']['path'] = $pantheon_home . 'files/civicrm';
$civicrm_paths['civicrm.files']['url'] = CIVICRM_UF_BASEURL . 'sites/default/files/civicrm/';
$civicrm_paths['civicrm.private']['path'] = $pantheon_home . 'files/private/civicrm';
$civicrm_paths['civicrm.private']['url'] = CIVICRM_UF_BASEURL . 'sites/default/files/private/civicrm/';
} else {
$civicrm_paths['civicrm.files']['path'] = 'path/to/files/civicrm';
$civicrm_paths['civicrm.files']['url'] = CIVICRM_UF_BASEURL . 'sites/default/files/civicrm/';
$civicrm_paths['civicrm.private']['path'] = '/path/to/files/private/civicrm';
$civicrm_paths['civicrm.private']['url'] = CIVICRM_UF_BASEURL . 'sites/default/files/private/civicrm/';
}
/**
* Override File directories and URLs.
*/
if (isset($_ENV['PANTHEON_SITE'])) {
// Override the Temporary Files directory.
$civicrm_setting['domain']['uploadDir'] = '[civicrm.private]/upload/';
// Override the Custom Files Upload directory.
$civicrm_setting['domain']['customFileUploadDir'] = '[civicrm.private]/custom/';
// Override the Images directory.
$civicrm_setting['domain']['imageUploadDir'] = '[civicrm.files]/persist/contribute/';
// Override the Image Upload URL (System Settings > Resource URLs)
$civicrm_setting['domain']['imageUploadURL'] = '[civicrm.files]/persist/contribute/';
}
/**
* Override the Resource URL
*/
if (isset($_ENV['PANTHEON_SITE'])) {
$civicrm_setting['domain']['userFrameworkResourceURL'] = '[civicrm.root]';
}
/**
* Extensions
*/
if (isset($_ENV['PANTHEON_SITE'])) {
// Override the Extensions directory.
$civicrm_setting['domain']['extensionsDir'] = '[cms.root]/civicrm_custom/extensions/';
// Override the Extensions Resource URL
$civicrm_setting['domain']['extensionsURL'] = '[cms.root]/civicrm_custom/extensions';
// Disable automatic download / installation of Extensions on live
if (isset($_ENV['PANTHEON_SITE']) && ($_ENV['PANTHEON_ENVIRONMENT'] == 'live')) {
$civicrm_setting['domain']['ext_repo_url'] = false;
}
}
/**
* Custom Template and PHP files.
*/
if (isset($_ENV['PANTHEON_SITE'])) {
// Override the Custom Templates directory
$civicrm_setting['domain']['customTemplateDir'] = '[cms.root]/civicrm_custom/custom_templates/';
// Override the Custom PHP directory
$civicrm_setting['domain']['customPHPPathDir'] = '[cms.root]/civicrm_custom/custom_php/';
}
// SSL
$civicrm_setting['domain']['enableSSL'] = TRUE;
$civicrm_setting['domain']['verifySSL'] = FALSE;
/**
* SMARTY Compile Check:
*/
if (isset($_ENV['PANTHEON_SITE']) && $_ENV['PANTHEON_ENVIRONMENT'] == 'live') {
define( 'CIVICRM_TEMPLATE_COMPILE_CHECK', FALSE);
}
/**
* Environment settings
*/
// Pantheon: if it's not the live site then send all emails to a log file
if (isset($_ENV['PANTHEON_SITE']) && $_ENV['PANTHEON_ENVIRONMENT'] != 'live') {
define('CIVICRM_MAIL_LOG', '[civicrm.private]/ConfigAndLog/mail.log');
}
/**
* Options: 'Production', 'Staging', 'Development'.
*/
$civicrm_setting['domain']['environment'] = 'Development';
if (defined('PANTHEON_ENVIRONMENT')) {
if (PANTHEON_ENVIRONMENT == 'live') {
$civicrm_setting['domain']['environment'] = 'Production';
} elseif (PANTHEON_ENVIRONMENT == 'test') {
$civicrm_setting['domain']['environment'] = 'Staging';
}
}
/**
* Redis cache if enabled.
*/
if (!empty($_ENV['PANTHEON_SITE'] && !empty($_ENV['CACHE_HOST']))) {
define('CIVICRM_DB_CACHE_CLASS', 'Redis');
define('CIVICRM_DB_CACHE_HOST', $_ENV['CACHE_HOST']);
define('CIVICRM_DB_CACHE_PORT', $_ENV['CACHE_PORT']);
define('CIVICRM_DB_CACHE_PASSWORD', $_ENV['CACHE_PASSWORD']);
define('CIVICRM_DB_CACHE_TIMEOUT', 3600);
define('CIVICRM_DB_CACHE_PREFIX', 'pantheon-redis-civicrm:');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment