Creates a drush command line interface for setting an environment for a site instance. Other modules may then change their logic depending upon the current active environment. The drush env-switch command also invokes a hook to allow each module to run additional required actions when switching environments.

The environment states are completely customizable and may be arbitrarily set to any value that makes sense for the project at hand. The recommended set of environment states are 'development', 'production', and 'readonly'.

NOTE: This module has no UI, and merely provides a simple helper to allow modules to invoke actions when switching environments. A user interface is completely possible for certain use cases. I will accept patches if anyone wants to provide them.


The following code snippet will disable developer modules when switching into production mode, and reenable them when switching back into development mode.

 * Implements hook_environment_switch().
function YOUR_MODULE_environment_switch($target_env, $current_env) {
  // Declare each optional development-related module
  $devel_modules = array(

  switch ($target_env) {
    case 'production':
      drupal_set_message('Disabled development modules');
    case 'development':
      drupal_set_message('Enabled development modules');

You would then switch environments by using drush env-switch development or drush env-switch production in the command line.

This is also extremely handy for managing permissions when combined with features.


The user ceardach is no longer available. Please contact arknoll or Grayside if you need assistance.

Project information