Rectifying the mysubsite.dev vs. mysubsite.com dilemma

By Erik , Mon, 06/06/2011 - 14:34
Drupal multisites are really powerful and a nice way to not have to have all of the core files duplicated for each site that you're working on on a development or local server. Drupal looks for settings.php in a number of places. The more exact of a match that it can find to your sites URL, the better. If your site's address is fun.mywonderfulsite.com the most specific sites/ directory that Drupal will look for is: sites/fun.mywonderfulsite.com. Then it will start working its way backward through the domain to find a match sites/mywonderfulsite.com. If it can't find a match, it will use the sites/default directory that comes shipped with Drupal. Having found a valid settings.php file, Drupal will look in the same folder for modules and themes. It will also look in sites/all and in the core modules or themes directories. Again, if the module/theme is duplicated, Drupal will use one found in the more specific directory. The sites/fun.mywonderfulsite.com/files directory is also typically where Drupal stores many uploaded and user contributed files. So this path is often included in settings and variables in the database. For this reason, transferring settings and content from local to development to production, it is very helpful if we can use the same directory on all of our machines. The problem is that our setup is running from http://mysubsite.dev but the "development" and "production" sites will be at http://dev.mysubsite.com and http://www.mysubsite.com respectively. Now, Drupal can handle serving both dev. and www. from sites/mysubsite.com, you can't server a different TLD from the same directory. To bypass Drupal's automatic multisite detection and to suggest a directory to be used, we turn to a small core patch for Drupal 6 that was wonderful enough to be included in Drupal 7 core. You can use the uploaded patch to create your own mappings. cd ~/Sites/drupal wget http://drupal.org/files/issues/d-6.20-directory-alias.patch patch -p0 d-6.20-directory-alias.patch This changes one Drupal core file and adds a new file example.sites.php in the sites directory. To use the new functionality, simply copy the example.sites.php file to sites.php and edit it. There's a lot of detailed explanation and documentation within the file, but the guts of it are at the bottom commented out and ready for our changes. Change the following code: #$sites = array( # 'devexample.com' => 'example.com', # 'localhost.example' => 'example.com', #); to be uncommented and map our existing url to the sites directory that we would prefer: $sites = array( 'mysubsite.dev' => 'mysubsite.com', ); Now, Drupal will serve up http://mysubsite.dev from the sites/mysubsite.com directory so that all paths and configuration variables will be set the same way we need to have them on production. Next: Keeping sites under control

Comments3

Regina (not verified)

12 years 7 months ago

Hi Erik,

A quick thank you from someone who is an expert on Windows servers and c# applications. My first time in Apache/Drupal! I read this and related posted to set-up a development environment on my MAC :) Very generously done.

Many thanks!

Regina

Regina (not verified)

12 years 7 months ago

Hi Erik,

Could you point me to the best practices for moving a site from a multi-site in a local development environment to single site on hosted server? I am trying to figure out if I need to put my site in the sites/default folder on the hosted server or if I make a new folder matching my URL/Domain sites/dev.mydomain.com, put my site in that new folder and leave the default folder there or delete the default folder. Thanks!

Regina

so, the best practice is to set up your local development env with the new domain and use sites.php to manage that.
Then on the final site use the sites/mydomain.com directory. You should leave sites/default but you don't need to put anything into it as long as your domain will be swept up by mydomain.com.