Migrating a Drupal site from a single site to multi-site install

In this post, I describe how to move a Drupal based website from a single site installation to a multi-site installation. The instructions are centred on Debian/Ubuntu, but should be easy to adapt to other setups.

Here at Kitson Consulting, we host a number of Drupal sites for our clients (and for ourselves, as this blog runs on Drupal). Hosting them in a multi-site environment greatly reduces maintenance headaches, as Drupal's upgrade process is fairly complicated, and upgrading several sites individually takes considerably longer than upgrading a single multi-site installation. Consequently, when setting up a new site, we tend to add it to the multi-site setup. Occasionally though, we need to migrate a Drupal site in from elsewhere, where it was originally set up as a single standalone site, and that's where this article comes in. I was unable to find a clear explanation elsewhere of the steps required, so I hope this article is useful to others in the same situation.

Getting started

For simplicity's sake, I will assume that you have a working single site install ("old" site) and a working multi-site setup (the "new" site), and that both are at the same version of Drupal. If they aren't, go away and upgrade one so that the versions match before continuing with this article, we don't want to make this any more complicated than necessary! I also assume that both sites are on the same server, although the steps are fairly straightforward to adapt if this isn't the case.
There are essentially four steps:

  1. Move the site configuration file.
  2. Move the site modules, themes, etc.
  3. Move the site files.
  4. Update the database references.

To start, set your old site to one of the default inbuilt themes, turn off all caching, page compression, etc, clear the caches, and turn on maintenance mode. Then log out.

Move files

In your multi-site install, create a folder called sites/example.com (where example.com is the address of the site you're moving).

  • Copy sites/default/settings.php for the old site to sites/example.com/settings.php for the new site.
  • Similarly, copy sites/all/themes (old) to sites/example.com/themes (new),
  • sites/all/modules (old) to sites/example.com/modules (new) and
  • sites/default/filesses/example.com/files (new).

Update database

Your website filesystem should now be correctly in place in the multi-site install. Now it's time to fix the database. Run the following commands on the site server, putting in the database password when prompted:

  1. mysqldump -u [site_database_user] -p [site_database_name] > old_site_database.sql
  2. sed s@sites/all/@sites/example.com/@g old_site_database.sql > new_site_temp_database.sql
  3. sed s@sites/default/@sites/example.com/@g new_site_temp_database.sql > new_site_database.sql
  4. mysql -u [site_database_user] -p [site_database_name] < new_site_database.sql

Briefly, these instructions dump the entire database to a text file, do a find/replace on "sites/all/" → "sites/example.com/" and "sites/default/" → "sites/example.com/", and then overwrite the database with the updated version.

Final steps

The database should now be sorted, so all that remains is to tell your webserver (I assume Apache) that the site lives in a different place now. Adjust your Apache config for the site to point from its old location to the new location, e.g. by opening /etc/apache2/sites-available/example.com and changing DocumentRoot /var/www/example.com to DocumentRoot /usr/local/share/drupal. Any Directory options and similar will also need to be edited. Run apache2ctl configtest to check there aren't any mistakes, and then run service apache2 reload to load the new config.

Congratulations! You should now be able to visit your site URL and see the site running correctly from its new multi-site home. Log in, re-enable your theme, turn compression and caching back on if you use them, and finally turn maintenance mode off. Ta-da!

Comments

Hi,

I followed this guide exactly as described, but still I'm not able to migrate my old single site to my new multi site. Having followed all described steps and trying to access my newly migrated (now multi site) site, I just get a white screen not showing anything. The apache error log says: "PHP Fatal Error: Call to undefined function user_access() in '/home/drupal/public_html/includes/menu.inc' on line 634. With that message, I'm kind of stuck. Am I missing any important step? I'm trying to migrate a drupal 7.27 minimal single site installation to a drupal 7.27 minimal multi site installation.

Any help would be highly apreciated! Thanks!

Hi Dominik,

That sounds like a general Drupal problem rather than a problem with the change to multi-site. Have you definitely copied across all of the modules and themes from your old install?

The only other thing I can suggest is to try to copy the site from its old single-site install to a new single-site install, and see whether the same issue appears. If so, then you can be sure it's a general Drupal problem rather than a multi-site specific problem.

Good luck!

Add new comment

(If you're a human, don't change the following field)
Your first name.
(If you're a human, don't change the following field)
Your first name.

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.