As a course of developing for larger Drupal sites, you typically find yourself having multiple environments, one for development, one or more for staging or user acceptance testing, and another for production (and perhaps disaster recovery).
One thing that always comes up is making Drupal “environment” aware, so it knows how it should behave, what modules should be turned on (or off) and what servers it should be talking to for instance.
The environment module allows you to define arbitrary environments (it also comes with some out of the box) in code. Example hook
You also may want to remove the default environments that come with the environment module
Using this code, and some magic in settings.php, you can effectively tell Drupal which environment it is by switching on the HTTP_HOST. A stripped back example is:
Note this also lets you include a separate PHP file called “settings.dev.php” for development, where variable overrides (using global $conf) can be done on a per-environment basis.
A natural extension of the environment module is to allow pulling a production database back to development, and then “switching” it into a development state. This switching is already a hook you can implement, allowing you to react on both the current and target environments.
An example of this is from the module’s homepage:
Other common things we do in our environment switch to development include:
Removing JS and CSS aggregation
Changing the Apache Solr environment to point at localhost
Preventing API writes to production systems
Granting helpful debugging permissions to certain roles
The list goes on here.
Environment indicator module
Now that Drupal is environment aware, it is really helpful if Drupal can inform the user what environment they are currently looking at. Out of the box the environment module has no UI, so enter the module environment indicator to come save the day.
The new 7.x-2.x branch of environment indicator contains a lot of improvements over the 7.x-1.x branch, one of which is the integration with the core toolbar and shortcut modules.
To illustrate this, here is a screenshot of our toolbar in development (some links were stripped)
The module also alters the favicon to include a tiny letter and coloured background to match the colour you chose
This way you will never again forget which environment you are using, as the colours will be right there at the top of every page.
I am keen to hear how other people solve the issue of environment aware Drupal applications, and how this is communicated to the end users of the application. What other modules are out there? What experiences have you had?