Last Updated: February 25, 2016
· timfernihough

Overriding Drupal variables in settings.php

Drupal uses the variable table in the database to store any variables set in Drupal. Most modules set at least one variable (core, contrib, custom, etc) and if they are doing things correctly, these are usually stored in the variable table and set using variable_set.

There may come a time where you need to override a specific variable but for one reason or another it might not be possible to run an update hook on your module or perhaps you just need another method.

The settings.php file of Drupal can be used to override variables set in the database. Any variable that has been defined with a:

variable_set('variable_name', 'somevalue');

statement can be overidden by creating an entry at the bottom of your settings.php file (or in settings.local.php if you use it) that looks like this:

$conf['variable_name'] ='a new value';

Any reference to this variable in your code will now get its value from this $conf definition. This include any variable_get statements.

For overriding domain specific variables if you're using Domain Access, I've got another post here.