Creating Local and Staging sites with Drupal's Domain Module Enabled
17th July 2013
The Domain Access project is a suite of modules that provide tools for running a group of affiliated sites from one Drupal installation and a single shared database. The issue is that the domains are stored within the database so these are copied across when the data is migrated between environments, whereas the domains are obviously going to change.
Rather than changing the domain settings within the Domain module itself, the best solution I think is to use table prefixes and create a different domain table per environment. With a live, staging and local domains, the tables would be named as follows:
live_domain local_domain staging_domain
Within each site's settings.php file, define the prefix for the domain table within the databases array so that each site is looking at the correct table for its environment.
$databases['default']['default'] = array( 'driver' => 'mysql', 'database' => 'foobar', 'username' => 'foo', 'password' => 'bar', 'host' => 'localhost', 'prefix' => array( 'default' => '', 'domain' => 'local_', // This will use the local_domain table. // Add any other prefixed tables here. ), );
Within each environment-specific domain table, update the subdomain column to contain the appropriate domain names.
Update: I've just found out about the Domain Alias sub-module, which you can enable and add aliases to each domain, so you could add the aliases in this way also.
About the Author
Oliver Davies is a Web Developer, System Administrator and Drupal specialist based in the UK. He is a Senior Developer at Microserve and also provides freelance consultancy services for Drupal websites, PHP applications and Linux servers.