Creating Local and Staging sites with Drupal's Domain Module Enabled
Warning: This post is over a year old. I don't always update old posts with new information, so some of this information may be out of date.
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.
Questions? Comments? I’m @opdavies on Twitter.
About the Author
Oliver Davies is a Full Stack Web Developer and System Administrator based in the UK. He is a Senior Software Engineer at Inviqa and a part-time freelancer specialising in Drupal, Symfony and Laravel development and Linux systems administration.