Last updated August 10, 2011.
I have been organizing my sites using the below method for some time. I just wrote a page documenting it. I was wondering if anyone else would find this helpful. If so, I would be willing to donate it to the documentation team. At any rate, I'd like to hear people's comments, both positive but especially negative ones.
I'll post a message to the docs team to point them at this page. You may also view this at http://software.davidlark.net/node/34 .
Advanced Multisite Configuration
Most people create Drupal sites the simplest and most obvious way:
- Sign up for a shared hosting account, using their primary domain name, taking advantage of the hosting provider's offer to register that domain name for free.
- Unpack the Drupal tarball into the public_html folder.
- Create subdomains and addon domains in their default locations.
- Intermingle any old HTML files with the Drupal files.
IMHO, this is just plain wrong, as it creates many problems and missed opportunities.
- If you register your domain with your web host, they might hold it hostage should things turn sour (as they often do).
- subdomain.example.com can be accessed through example.com/subdomain . The same goes for addon domains.
Upgrading can be an excruciating experience, as you must take all the sites offline until the upgrade is complete:
- Put all the sites into mainenance mode.
- Backup the databases and files.
- Delete the old Drupal files.
- Unpack the new Drupal tarball into public_html.
- Run update.php on all sites.
- Verify that the sites function and put them back online.
- Recovering from a failed upgrade can be even more excruciating, as you must restore everything you deleted.
- You might think of something to do with the free domain name.
Achieving Directory Location Freedom for Your Domains and Drupal Installations
- Invent a meaningless domain name, such as SixRandomLetters.com . Create the hosting account using this name, allowing the webhost to register this for you for free.
- Place an index.html file in your public_html directory with some meaningless content in it.
- Create a directory in your home directory called "DrupalInstalls". Unpack the Drupal tarball into this directory, creating the directory "/home/sixrandomletters/DrupalInstalls/drupal-x.y".
Determine, through scientific investigation (trial and error), how much flexibility your webhost allows in the location of subdomains and addon domains.
- If your webhost allows you to place domains directly under your home directory, create your primary domain through the control panel, pointing it at the Drupal directory.
If your webhost requires you to place domains under public_html, but allows you to nest these in another directory:
- Create a directory in your public_html directory named "Domains".
- Create your primary domain through the control panel as an addon domain, pointing it at a new directory under "Domains" (for example.com this might be "/home/sixrandomletters/public_html/Domains/example").
- Rename the new directory "example.dir".
- Create a symbolic link from "/home/public_html/Domains/example" to the Drupal directory.
If your webhost requires you to place domains directly under the public_html directory, you'll just have to live with it.
- Create your primary domain through the control panel, pointing it at a new directory under "public_html" (for example.com this might be "/home/sixrandomletters/public_html/example").
- Rename the new directory "example.dir".
- Create a symbolic link from "/home/public_html/example" to the Drupal directory.
- Create a database through the control panel. This will become the default installation, and will probably only be accessed should someone surf to "sixrandomletters.com/Domains/example.
- Surf to the new site. You should see the familiar Drupal installation pages. Follow the familiar procedure. Create an article of meaningless content.
- Create another database.
- Create a folder under the Drupal sites directory to contain the settings for the new site (/home/DrupalInstalls/Drupal-x.y/example.com).
- Copy the settings.php file from the default installation to the new directory.
- Modify the new settings.php file to point to the new database.
- Surf to the site again, and run through the installation procedure. This will become your new primary domain.
- Create directories as needed under the new site directory for modules, themes, and files.
Follow these steps for every other subdomain or addon domain that you need to make:
Repeat one of these sequences under step 4 above, depending on your situation, substituting the proper information:
- 4B steps 2,3, and 4
4C steps 1-3
Note that you can copy the existing symbolic links instead of creating new ones if you find that easier.
- Repeat steps 7, 8, 9, 10, 11, and 12 above.
- Repeat one of these sequences under step 4 above, depending on your situation, substituting the proper information:
Achieving Directory Location Freedom for Your Configuration Data, Images, Media, and Static Files.
To Separate Out the Sites Directory:
- Move the sites directory from the Drupal directory to your home directory.
- Rename this directory to reflect the major version of Drupal, i.e. D7Sites for Drupal 7.
- Create a symbolic link from the Drupal directory to the relocated directory (~/Drupal-Installs/Drupal-x.y/sites => ~/D7Sites).
To Separate Out Static Files:
- Create a directory named "StaticFiles" in your home directory.
- Create a symbolic link from your Drupal directory to the new directory. Give it a short name like "mix" (~/Drupal-Installs/Drupal-x.y/mix => ~/StaticFiles).
- Place any static content into this directory. You can now access it at "example.com/mix/staticfile.html". Note that it can be accessed similarly through all your domains.
(Optional) Separate the static files out by site:
- Create a directory in the "StaticFiles" directory, naming it with the name of the domain it serves (~/StaticFiles/example).
- Move the static files for this domain into the new directory. You can now access them through "example.com/mix/example/staticfile.html".
- (Optional) Create rewrite rules in your .htaccess file to shorten the URL and direct requests from a particular domain to the proper folder.
Regarding File Handling:
You may wish to separate out files in a similar manner, especially if you have a large file repository system. However, Drupal's recommended practice (http://drupal.org/documentation/modules/file) is probably adequate.
Finding a Use for Your Free Domain Name
You can create and delete e-mail accounts at will, to trap spam or provide some anonymity.
Your New Upgrade Procedure:
- Unpack the new Drupal tarball into your DrupalInstalls directory, creating a new Drupal directory next to the old one.
- Copy the link to the sites directory from the old Drupal installation to the new one.
- Copy the link to the StaticFiles directory from the old Drupal installation to the new one.
For each site, starting with the least critical one (perhaps a test/development site):
- Put the site into maintenance mode.
- Backup the database. Backing up files is optional.
Point the domain at the new drupal installation using one of these methods:
- If your subdomain is pointed directly at the Drupal directory, and you are able to do so, change the Document Root for the domain using your control panel.
- If your subdomain is pointed directly at the Drupal directory, but you are not able to change the Document Root, delete the existing subdomain and recreate it.
- If your subdomain points to a link which points to the Drupal directory, and you are able to do so, change the link target. WinSCP allows you to do this.
- If your subdomain points to a link which points to the Drupal directory, and you not able to change the link target, delete the existing link and recreate it. Once you have done this once, you may copy the working link to other domains.
- Run update.php .
- Verify that the site works, and put it back online.
- When you are satisfied that your sites are performing properly, you may delete the old Drupal installation.
Now you can see the advantages! Instead of destroying the old installation before you create the new one, you can run them side-by-side. Instead of deciding which files to delete, all you do is copy a couple of links. Instead of taking down all your sites while you upgrade them all, you can upgrade them one at a time at your leisure.
Note that if you have an existing Drupal installation, with the exception of the garbage domain name, you can migrate to this system during the course of a minor upgrade.
Major Version Upgrades
Of course, you must go over the upgrade.txt file before you undertake this major life event, and determine what needs to be done for your specific site. However, you can still upgrade one domain at a time. I suggest creating a new sites directory for each major version.