Keep Local Database and Filesystem Settings in a Site-specific settings.php

A common development practice is to keep a local web server running on your laptop, or a development/staging server. A feature of Drupal designed for multisite installations can actually help you out in this situation.

Different servers often mean different databases, database users, and passwords. Sometimes, you may also need to point to a different files/ directory or tmp/ directory, especially if you are moving between Windows to Linux, or a local machine to a server.

In this case, you need to make a separate directory inside ./sites/, usually ./sites/localhost/ - then make a copy of settings.php from the default/ folder and place it in this new folder.

Change your database username and password as usual (see INSTALL.txt if you're lost), but also take a look at the $conf settings at the bottom of settings.php - this is where some of the magic can happen. Any setting stored in a variable - which is how most modules (especially core modules) store settings - is available to modify inside the $conf array.

Example: changing the files path and the temp directory:
$conf = array(
'file_directory_path' => 'sites/default/files',
'file_directory_temp' => '/tmp',

Now there's no need to visit Sites > Settings > File System on each site when you move databases around, just modify this file on each new server.

Also, think about setting cache settings here:
$conf = array(
'cache' => FALSE, //page cache
'block_cache' => FALSE, //block cache
'preprocess_css' => FALSE, //optimize css
'preprocess_js' => FALSE, //optimize javascript

The above settings will turn off all cache settings.

You can set lots more in this file. See this related DrupalEasy quicktip for more info.


[...] you are showing PHP errors on the screen, if this is an option. This is the kind of thing you can edit in your site-specific settings.php file, by [...]

Sign up to receive email notifications of whenever we publish a new blog post or quicktip!