Setting up MCFileManager on Drupal 7 with Capistrano

I needed to install MCFileManager on a capified Drupal 7 project.  I followed these instructions, but changing the upload directory and getting things to work with Capistrano was slightly complicated.  Here are a few lessons I learned…

1. The filemanager module must be installed in /sites/all/modules

I’ve been installing all contributed modules in /sites/all/modules/contrib, but this didn’t work with filemanager.  There’s probably a workaround, but I didn’t take the time to figure it out.

2. By default, MCFileManager will upload files to /sites/all/modules/filemanager/files

We use git for version control and I’ve been using the amazing Capistrano ruby gem to deploy.  To keep things manageable and consistent, I like to keep all of my uploaded files in my .gitignored /sites/default/files/ directory.

To set this up, I converted the /sites/all/modules/filemanager/files directory into a symlink to /sites/default/files/filemanager like this:

# cd into the document root, then...
mkdir sites/default/files/filemanager
# backup the default filemanager upload directory
mv sites/all/modules/filemanager/files sites/all/modules/filemanager/files.bak
# symlink /sites/all/modules/filemanager/files to sites/default/files/filemanager
cd sites/all/modules/filemanager && ln -s ../../../default/files/filemanager files

This worked in my local dev environment, but I had issues after I deployed to my staging environment.

Turns out that MCFileManager doesn’t play well with symlinks.  Since Capistrano relies on symlinks, things were broken.  I could upload files through MCFileManager, but it generated broken links.  Not good.

To make things work on the staging server, I had to set the following values in my filemanager/config.php file:

$mcFileManagerConfig['preview.wwwroot'] = 'files';
$mcFileManagerConfig['preview.urlprefix'] = "/sites/default/files/filemanager";
...
$mcFileManagerConfig['filesystem.path'] = 'files';
$mcFileManagerConfig['filesystem.rootpath'] = 'files';

After a few hours of Googling, trial, and error, my WYSIWYG file uploader works!

Comments are closed.