Drupal was originally designed for configuration and content authoring via the web interface directly in the production environment. As Drupal is adopted more widely, it requires support for multiple environments. A development environment provides a place to experiment with configuration and code custom modules. An integration environment allow the work of multiple developers to be tested together. A stage environment can be used for functional testing, performance testing, quality assurance (QA), user acceptance testing (UAT), demonstration, and content author training. This article discusses tools and techniques that make it possible to build, configure and deploy Drupal sites across multiple environments.
Generally, code and configuration flows from development to production. Content flows in the opposite direction, from production to development.
Drupal stores both content and configuration in the database. This workflow has become possible with tools that allow Drupal configuration to be exported from the database and stored in code. Once in code, configuration can be easily replicated in all environments via code deployment.
The source code repository is the "database of record" for site code and configuration. It contains the "master" or "trunk" branch currently deployed in production, as well as branches for other environments and work in progress. For added convenience in deployments, Drupal core and contrib modules can be committed to your repository, in addition to any custom modules and themes.
The Production database is the "database of record" for site content. Site authoring occurs in the production environment. The stage environment can be used for content author training. Since content created in stage is not preserved, this is a good environment for content author learning and experimentation.
Drupal Core Tools
settings.php - Separate settings.php files for each environment can be used for database connections and other PHP settings which may vary between environments. Create a subdirectory under the /sites directory with the domain name for each environment, such as /sites/stage.example.com/settings.php.
Settings.php should only be used for environment-specific configuration. Configuration common to all environments should not appear in settings.php.
Installation profile - An install profile is a predefined collection of modules, themes and configurations. This is a great way to setup your site in a new environment with specific modules enabled and configured. Instructions for building install profiles can be found at https://drupal.org/developing/distributions. You can also download existing installation profiles from https://drupal.org/project/distributions.
Features - Instead of manually repeating configuration steps for each environment, Features exports configuration as custom module code. Committing this code to your repository allows for the easy migration of configuration from one environment to others. Features is widely supported by other contrib modules.
Features Extra - Export taxonomy vocabularies and terms, node queues, and blocks into code.
UUID Features Integration - Used to export content (nodes, taxonomy, fields) with features. Best used for content that is configuration-like, such as taxonomy terms.
Strongarm - Strongarm is used to export Drupal variables to code for migration to other environments.
Backup and Migrate - Quickly backup and restore a Drupal database right from Drupal's web interface using local storage, FTP, Amazon S3, or Email. You can also perform scheduled backups. This module can be used to backup content in production and restore in other environments.
Reroute Email - This module intercepts all outgoing emails from a Drupal site and reroutes them to a predefined configurable email address. This is particularly useful in development, integration and stage environments, where you don't want emails being sent to production users.
Drush - Short for DRUpal SHell, Drush is a powerful command line utility with widespread module support. Use Drush to manage cache, cron, variables, download and enable modules, run SQL, execute PHP, and much more. Drush is an essential tool for any Drupal developer or system administrator.
Drush Make - A Drush Make file contains a list of modules, themes and profiles to be included in a Drupal project. It's a recipe for building a Drupal site, just as .info files are a recipe for individual Drupal modules. The components detailed in the make file can be pulled from multiple sources, such as drupal.org, third-party library sites or private locations. If you wish to store only custom modules and themes in your source code repository, a versioned make file contains the instructions for downloading Drupal core, contrib modules and libraries from their source.
Platform as a Service - Some Drupal hosting providers have extended their hosting offerings to form a "platform as a service"". These services frequently include source code repositories and extra tools for code, configuration and content deployments. Acquia and Pantheon both offer such toolsets. A list of PAAS offerings is available at https://drupal.org/hosting/paas.
Deploy - The deploy module deploys content from one site to another. Your stage environment becomes a content authoring and preview platform, deploy moves content to production when you wish to publish it. In this case, stage becomes the "database of record" for content. This works best when all content is authored in stage and then deployed to production. This method may not be ideal for sites with User Generated Content (UGC) or other content created in production. This module is alpha and may require strong technical support for complex content types.