background image
HomeRecent PostsDrupalSearchTagsRSSContactAboutAccount
Eric.London's picture

In this article, I'll explain how I converted my site from using sites/default/files to a specific sites folder, IE: sites/ericlondon.com/files. This is essential for setting up a Drupal mulit-site installation, which allows you to host numerous Drupal sites off a single Drupal installation. When creating a new site/project, I think it's important to ask yourself: will this client/project ever require another Drupal site? In my recent history, I have found it's safer to implement a site-specifc sites folder for each project from the start, to keep the configuration segmented. Here is an example filesystem layout:

Contrib modules that are shared across all client/project sites:
sites/all/modules/contrib

Custom modules that are shared across all client/project sites:
sites/all/modules/custom

Site-specific files directories:
sites/project1.com/files/
sites/project2.com/files/

Custom modules that are site specific:
sites/project1.com/modules/custom/
sites/project2.com/modules/custom/

For my site, I used the Site Directory Migrate module. I downloaded the module and unpacked to: sites/all/modules/contrib/sitedir_migrate. This module comes with a bunch of submodules to help the migration (profile fields, CCK, blocks, etc). I chose to enable all of them for my site.

After installing the module, I browsed to the configuration page (admin/settings/sitedir_migrate), entered "default" in the "From:" field, and entered "ericlondon.com" in the "To" field. By saving this page, the module searches your database for instances of your previous sites directory and replaces the data with the new sites folder.

I then browsed to the File System admin page (admin/settings/file-system), and changed my file system path from "sites/default/files" to "sites/ericlondon.com/files", and saved. You can now disable the Site Directory Migrate modules.

At this point, your content will be adjusted, but you still need to reconfigure your Drupal installation. On the command line, I moved the contents of my previous sites folder to the new one.

$ cd /path/to/drupal/installation/httpdocs/sites
$ mkdir ericlondon.com
$ mv default/settings.php ericlondon.com/
$ mv default/files ericlondon.com/

Now that everything has been reconfigured, I flushed all my caches, and started to verify my content. I immediately noticed my content's teasers had not been adjusted, IE: teaser images were still pointing to: sites/default/files.

I decided to use SQL to blindly update all of my teasers (probably not the best solution, but it worked for me).

update node_revisions
set teaser = replace(teaser, 'sites/default/files', 'sites/ericlondon.com/files')
where teaser like '%sites/default/files%'

NOTE: If you have phpMyAdmin installed for your site, it has a great feature that allows you to search through all of your tables for a specific string. This can be used to help find additional records that need to be adjusted.

Eric.London's picture

Drush is a great command line module for administering a Drupal site. It's core features are listed here. Check out the README.txt for usage and installation documentation.

Drush can be used to setup a base Drupal installation with a few quick commands, awesome. One of it's biggest time saving features is downloading all the contributed modules when setting up a new site. Here are a few commands I use to setup a new Drupal site based on feature sets. The following commands should be run in the root directory of your drupal installation.

# Download development modules and themes:
drush dl admin admin_menu coder devel devel_themer reroute_email simpletest views_bulk_operations --destination=sites/all/modules/contrib/ --uri=http://yourhostname.com

# Download common/essential modules:
drush dl cck views date wysiwyg pathauto token captcha recaptcha location emfield link jquery_ui webform htmlpurifier luceneapi vertical_tabs --destination=sites/all/modules/contrib/ --uri=http://yourhostname.com

# Download SEO modules:
drush dl google_analytics xmlsitemap globalredirect site_verify --destination=sites/all/modules/contrib/ --uri=http://yourhostname.com

# Download structural/building modules:
drush dl context features ctools panels --destination=sites/all/modules/contrib/ --uri=http://yourhostname.com

# Download image handling modules:
drush dl imageapi transliteration filefield mimedetect imagefield imagecache imagecache_actions --destination=sites/all/modules/contrib/ --uri=http://yourhostname.com

NOTE: the destination and uri flags on the drush command are optional, but I recommend using them. In recent Drupal development I stopped using sites/default in favor of sites/hostname.com, to ensure that if I ever decide to move the site into a multi-site configuration, I will not have overlapping sites/default/files directories.

You can even enable the downloaded modules from the command line by using the "drush en" command..

drush help en

Syndicate content