Restored guide

Converting a site that uses sites/default/files to a site-specific configuration per Drupal multi-site installations

February 21, 2011 · 2 min read · Eric London's Drupal Blog

A Drupal multi-site install keeps code in one tree and gives each domain its own settings and files. This note is the move from a single site that still writes into sites/default/files to a directory named for the site.

What you are solving

Drupal chooses the site folder from the HTTP host. If that folder has no files directory and no file-system path of its own, uploads keep landing in sites/default/files. Two domains then share derivative images, private attachments, and the temporary path. Split them before the second site has real content.

Create the site directory

For a site answering example.com, Drupal 6 looks for sites/example.com. Copy only what belongs to that site: settings.php and the files you are about to move. Leave modules and themes in sites/all unless one site truly needs a private copy.

mkdir -p sites/example.com/files
chown -R www-data:www-data sites/example.com/files

Point the file system at it

In Drupal 6 the public path is stored in the file_directory_path variable and configured at Administer, Site configuration, File system. Set it to sites/example.com/files. Move existing uploads with rsync, then request one known image and one ImageCache derivative.

rsync -a sites/default/files/ sites/example.com/files/

Database records often store a path relative to that variable, not a full URL. If you used the same relative layout, the records do not need a rewrite. If a field stored sites/default/files/... as a literal, search the field tables on a copy and update that prefix before you cut DNS.

Settings and the temporary directory

Give the site its own temporary directory outside the web root when you can. Confirm settings.php for the new folder is the one Drupal loaded. A quick check is a unique $conf value or a one-line watchdog entry from settings.php that you remove after the test.

Check before you deploy

  • Upload a file while browsing the new host and confirm it lands in the new directory.
  • Open an old public file and an ImageCache URL.
  • Leave sites/default/files in place until the logs show no reads, then archive it.

Restored guide for the 21 February 2011 note on multi-site file directories.