Maintaining different settings on different environments with Drush
On nearly every site I have ever worked on there has been one or two settings that I wanted set differently on dev as compared to prod. Of course I could just set the settings locally, however every time I would bring the production database down those settings would be overridden. For example I always want to have the devel module enabled locallay to —ya know— help me devel, but I amost never want it enabled on production. To solve this problem I've written a simple Drush command called "environmnet." Here's how it works…
Installing is easy…
- First things first, follow these instructions to clone the Drupal sandbox project so that the environment.drush.inc file lives in your sites/all/drush folder. What's that, you don't HAVE a sites/all/drush folder!? Now's the time to make one.
- Next, open (or create) sites/all/drush/drushrc.php and add the following code (modify to taste):
// Add this to your drushrc file and modify as needed. // The option key MUST be enviroments. $options['environments'] = array( // #key = The enviroment name. 'dev' => array( // The list of modules to enabled (1) or disable (0). 'modules' => array( 'views_ui' => 1, 'devel' => 1, 'memcache' => 0, ), // The list of variables to configure. 'settings' => array( 'preprocess_css' => 0, 'preprocess_js' => 0, ), // The list of roles to grant (1) and revoke (0) on a per role basis. 'permissions' => array( 'Administrator' => array ( 'administer permissions' => 1, ), 'anonymous user' => array ( 'administer permissions' => 1, ) ), ), 'prod' => array( // The list of modules to enabled (1) or disable (0). 'modules' => array( 'views_ui' => 0, 'devel' => 0, 'memcache' => 1, ), // The list of variables to configure. 'settings' => array( 'preprocess_css' => 0, 'preprocess_js' => 0, ), // The list of roles to grant (1) and revoke (0) on a per role basis. 'permissions' => array( 'Administrator' => array ( 'administer permissions' => 1, ), 'anonymous user' => array ( 'administer permissions' => 0, ) ), ), );
...and that's it. Well, almost. Now we have to run the command:
drush environment prod
Running this command (based on the example code above) will disable the views_ui & devel modules; enable the memcache module; turn on preprocess_css & preprocess_js by setting those variables; and turning on/off the "administer permissions" for different roles.
Alternatively, give this command a try:
drush environment dev
...and you'll see that (based on the example code above) the views_ui & devel modules will be enabled; the memcache module will be disabled; preprocess_css & preprocess_js is disabled; "administer permissions" is turned off/on for different roles.
Suggestions welcome.