Personal reminder about Drupal's settings.php

Share and options

Because I often duplicate a production site on a local machine in order to do some debugging/bugfixes, I like everything to be ready the sooner as possible without having to do a lot of clicks.

Here is how I override values in my custom settings.php file instead of loosing time clicking into the administration pages or even doing configuration alteration with Drush.

Here is a common production site settings.php $conf variable alteration :

<?php
// Production site settings
$conf['block_cache'] = 1;
$conf['cache'] = 1; // 1 is normal cache mode
$conf['cache_lifetime'] = 0; // 0 is infinite
$conf['clean_url'] = 1;
$conf['error_level'] = 0; // O means dblog only, better not display those errors to end users
$conf['file_directory_path'] = '/var/www/myhost/var/tmp';
$conf['file_directory_temp'] = 'sites/default/files';
$conf['file_downloads'] = 1; // 1 is PUBLIC, most sites will use this
$conf['preprocess_css'] = 1;
$conf['preprocess_js'] = 1; // Set to 0 in case you have some JS errors
$conf['site_403'] = ''; // Leave empty for default drupal message
$conf['site_404'] = ''; // Leave empty for default drupal message
$conf['site_mail'] = 'webmaster@somepublicdomain.tld';
$conf['page_compression'] = 1;
?>

Common variables overrides in the settings.php is usally a good idea. Because this file is protected (first thing), it's more secure, and because sysadmins which deploy web sites does not want to click everywhere, it's easier for them to do a final configuration phase using this file instead of using the Drupal administration pages.

Most of these settings (except the site_403 and site_404) and environment-related, not integration-related. So the settings.php is the best place for them to live.

Now, I am a developer, and I just copied the production environment on my box in order to do some debug, how could I get a development environment the fastest way possible? By overriding the settings.php!

So, I'm just going to add my own variables (not even remove the production site ones, can be useful to keep them here so I can consult it) :

<?php
// Production site settings
$conf['block_cache'] = 1;
$conf['cache'] = 1; // 1 is normal cache mode
$conf['cache_lifetime'] = 0; // 0 is infinite
$conf['clean_url'] = 1;
$conf['error_level'] = 0; // O means dblog only, better not display those errors to end users
$conf['file_directory_path'] = '/var/www/myhost/var/tmp';
$conf['file_directory_temp'] = 'sites/default/files';
$conf['file_downloads'] = 1; // 1 is PUBLIC, most sites will use this
$conf['preprocess_css'] = 1;
$conf['preprocess_js'] = 1; // Set to 0 in case you have some JS errors
$conf['site_403'] = ''; // Leave empty for default drupal message
$conf['site_404'] = ''; // Leave empty for default drupal message
$conf['site_mail'] = 'webmaster@somepublicdomain.tld';
$conf['page_compression'] = 1;

// Overrides for development site (disable all caches)
$conf['block_cache'] = 0;
$conf['cache'] = 0; // 0 is no cache mode
$conf['cache_lifetime'] = 0; // 0 is infinite
$conf['error_level'] = 1; // 1 means errors get to the end user
$conf['file_directory_path'] = '/var/www/mydevelopmenthost/var/tmp';
$conf['file_directory_temp'] = 'sites/default/files';
$conf['preprocess_css'] = 0;
$conf['preprocess_js'] = 0;
$conf['site_mail'] = 'developer@someinternaldomain.tld';
$conf['page_compression'] = 1;
?>

Hop, fast, reliable, centralized.