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.
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:
- Move the site configuration file.
- Move the site modules, themes, etc.
- Move the site files.
- 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.
In your multi-site install, create a folder called
sites/example.com (where example.com is the address of the site you're moving).
sites/default/settings.phpfor the old site to
sites/example.com/settings.phpfor the new site.
- Similarly, copy
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:
mysqldump -u [site_database_user] -p [site_database_name] > old_site_database.sql
sed s@sites/all/@sites/example.com/@g old_site_database.sql > new_site_temp_database.sql
sed s@sites/default/@sites/example.com/@g new_site_temp_database.sql > new_site_database.sql
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.
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!