Dev Sites & sites/x/files on a multi-site install - What's a good approach?
I have several sites installed as a Drupal multi-site install.
The Challenge
Files for the various items are found at:
/home/user/domain1.com/sites/domain1.com/files
/home/user/domain1.com/sites/domain2.com/files
etc.
However sometimes I need to set up a dev site that isn't live with files at:
/home/user/domain1.com/sites/dev.domain3.com/files
domain3.com remains un-multisited/un-symlinked as a
'coming soon' domain at /home/user/domain3.com until we go live.
When I go live with the site, I copy everything in
/home/user/domain1.com/sites/dev.domain3.com/
to /home/user/domain1.com/sites/domain3.com/, duplicate the db for domain3.com
from dev.domain3.com, and change settings.php at
/home/user/domain1.com/sites/dev.domain3.com/settings.php
to reflect the new db. Set up symlinks where the parked domain was,
and we're live.
When I navigate to Site Configuration --> File Settings, field 'File system path is
still obviously at sites/dev.domain3.com/files. Also, all documents attached via
'File Attachments' to page content are also hard-linked in the mysql system to
sites/dev.domain3.com/files. This frustrates me no end, because it means I have
to change all those links in the content for various images and pages from the dev
path to the live path.
To further complicate things, CiviCRM prefers to have its site-specific files at
sites/domain3.com/files and my theme puts a css file in the files folder.
I'd rather not have sites/domain3.com/files/civicrm or
sites/domain3.com/files/mythemefolder being visible through fck editor.
Lastly, I'd like to share some files between multisite installs.
The Approach
For purposes of development it seems appropriate to put the files I want to link to
at something like /home/user/domain1.com/sites/domain3 where 'domain3' is
'sites/domain3' in 'File system path' at Site Configuration --> File Settings.
That way, all the links remain the same when I transfer from dev to live.
CivicCRM's file placement defaults always to sites/domain3.com/files/civicrm
regardless of where 'File system path' directed, so in this case, fckeditor
would not be privy to the civicrm folder, since the File system path is designated
outside of the default sites/domain3.com/files.
However, mythemefolder is dependent on the current File system path,
so I would copy that into sites/domain3/mythemefolder and just live with it.
For shared files, I'd create a folder /home/user/domain1.com/sites/shared
and symlink this folder to /home/user/domain1.com/sites/domain3/shared
(and /home/user/domain1.com/sites/domain2/shared, etc.)
Is there anything in this approach that is likely to break a future version of Drupal?
Is this a good or bad approach?
Is there a better way of setting up file attachments in multisites?

Files on multi-site installs
Hi,
I've described the way I deal with the files folder location with symlinks for dev and prod sites in an earlier comment: http://drupal.org/node/463452#comment-1591966.
This avoids the problems with the domain being hard-coded in links in the content. FCKeditor is generally just pointed to an 'images' subfolder of the files folder, which means other files don't show up in its image browser. However, I'm not sure if this would get around your problems with CivicCRM, although it sounds like it might work, but I don't think you would be able to share files between sites, so it doesn't completely solve your problem ... unless you have a 'shared' subfolder in each site's files folder which is symlinked to a shared folder (although file permissions might become a hassle at that point!)
Best Practices?
matkeane,
Thanks for your reply.
You've suggested this:
/files <- Drupal's shared file folder
/files/site1 <- symbolic link to site one's file folder
/files/site2 <- symbolic link to site two's file folder
Just to be sure we're talking the same language, comparing with my situation:
/home/user/domain1.com/sites/all/files/ <- Drupal's shared file folder
/home/user/domain1.com/sites/all/files/domain3.com <- whateverfiles in this folder...
/home/user/domain1.com/sites/all/files/shared <- Files shared commonly across domains.
The actual multisite File system paths:
/home/user/domain1.com/sites/domain3.com/files will only be used by civicrm.
/home/user/domain1.com/sites/files/domain3.com is where File system paths will be directed.
/home/user/domain1.com/sites/files/domain3.com/files/shared
is a symlink to:
/home/user/domain1.com/sites/all/files/shared
Put the File system path to:
sites/files/domain3.com (or again, maybe domain3)
So when I set up File system paths for the dev site, I'll use
sites/files/domain3.com (or again, domain3)
and when I switch it to the live site, all the site paths will still be fine.
To further be clear, this the solution and the one I've suggested are
both apparently not considered best practices according to:
http://drupal.org/node/463452#comment-1670426
in the same thread you referred to.
I don't mind backing up two places. The same would be true of either solution.
As best practices go, though, it makes me wonder why 'File system path'
would be included if users weren't encouraged to use something other than
the default. Is:
/home/user/domain1.com/sites/domain3
any better or worse practices to put files than:
/home/user/domain1.com/sites/all/files/domain3.com
or
/home/user/domain1.com/sites/domain3.com/files
???
(sites/domain3 will be a shorter url than sites/all/files/domain3.com, too.)
Is either of these methods so remote from best practices that it's going
to come back to bite me later when Drupal metamorphoses into something
even more incredible?
Files folders
Hi,
I don't think I suggested anything too far removed from best practices. I just had another look at the handbook page and it mentions the use of symlinks to point to a files folder stored in a different place on the server, which is basically what I'm doing.
From the point of view of tidyness, logic and backing up, it makes sense to keep a site's files in its own files folder, so '/sites/example.com/files/' but, as you've seen, that makes for long paths with the domain embedded in them. The shortest file path is just 'files', which is what Drupal uses by default, I think, and results in all files being dumped into the '/files' folder in the Drupal root. A symlink from one to the other seems to give the best of both worlds - short paths without a domain embedded (just a nickname for the site) and files kept under each site's folder:
httpdocs/ <- webserver root folder with Drupal installhttpdocs/files/
httpdocs/files/example <- symlink to httpdocs/sites/example.com/files/
httpdocs/sites/all/modules/
httpdocs/sites/example.com/
httpdocs/sites/example.com/files/
If you look at the handbook page - http://drupal.org/node/53705 - again, it does say that "Note that there shouldn't be a /sites/all/files". I have to admit, I'd never thought of trying that. I don't follow the handbook's suggestion of having a '/sites/default/files' folder though, but there really shouldn't be a case where a domain name doesn't resolve to a site folder thanks to extra rewrite rules in Drupal's htaccess.
What I'm wondering, for sharing files across domains, is whether you could do:
httpdocs/files/shared/httpdocs/sites/example.com/files/shared <- symlink to the '/files/shared/' folder above
httpdocs/sites/example2.com/files/shared <- symlink to the '/files/shared/' folder above
... so that users would see 'shared' as a subfolder of their site's files. But I have a nagging feeling that, even if it works, it might be a bad idea!
In any case, I can't see that using symlinks would be a problem if D7 turns out to do things a different way. If we're supposed to put all files in a completely different folder, what's to stop you just changing the symlinks to point there instead? The symlink method has survived the upgrade from D5 to D6 OK!
A solution...
matkeane
I've had to mull this over. Thanks for your patience.
I think I get it now.
This is what I'm going to do:
$ pwd
home/user/httpdocs
$ ln -s ./sites/domain1.com/files dom1
$ ln -s ./sites/domain2.com/files dom2
$ ln -s ./sites/domain3.com/files dom3
$ ls -Gg
total 248
-rw-r--r-- 1 42 2009-07-01 13:51 CHANGELOG.txt
-rw-r--r-- 1 1 2008-02-06 04:45 COPYRIGHT.txt
-rw-r--r-- 1 2 2007-11-19 11:53 INSTALL.mysql.txt
-rw-r--r-- 1 2 2007-11-26 08:36 INSTALL.pgsql.txt
-rw-r--r-- 1 16 2008-07-09 12:15 INSTALL.txt
-rw-r--r-- 1 18 2009-01-06 09:27 LICENSE.txt
-rw-r--r-- 1 2 2009-04-29 10:15 MAINTAINERS.txt
-rw-r--r-- 1 5 2008-01-04 08:15 UPGRADE.txt
drwxrwxr-x 2 4 2009-02-18 13:50 cgi-bin
-rw-r--r-- 1 1 2006-08-09 00:42 cron.php
-rw-r--r-- 1 0 2009-07-07 16:54 favicon.gif
-rw-r--r-- 1 0 2009-07-07 16:54 favicon.ico
lrwxrwxrwx 1 1 2009-07-07 16:29 dom1-> ./sites/domain1.com/files
lrwxrwxrwx 1 1 2009-07-07 16:29 dom2 -> ./sites/domain2.com/files
lrwxrwxrwx 1 1 2009-07-07 16:29 dom3 -> ./sites/domain3.com/files
drwxr-xr-x 2 4 2009-07-07 17:32 includes
-rw-r--r-- 1 1 2007-12-26 00:46 index.php
-rw-r--r-- 1 46 2009-04-27 03:50 install.php
drwxr-xr-x 3 4 2009-07-01 13:55 misc
drwxr-xr-x 35 4 2009-07-01 13:55 modules
drwxr-xr-x 3 4 2009-07-01 13:55 profiles
-rw-r--r-- 1 2 2008-12-10 12:12 robots.txt
drwxr-xr-x 2 4 2009-07-01 13:55 scripts
drwxr-xr-x 6 4 2009-07-07 16:07 sites
drwxr-xr-x 7 4 2009-07-01 13:55 themes
-rw-r--r-- 1 25 2009-03-30 04:15 update.php
-rw-r--r-- 1 1 2005-12-10 11:26 xmlrpc.php
At http://www.domain1.com/admin/settings/file-system
change 'File system path' to 'dom1'.
At http://www.domain2.com/admin/settings/file-system
change 'File system path' to 'dom2'.
At http://www.domain3.com/admin/settings/file-system
change 'File system path' to 'dom3'.
This is similar to what you are suggesting, but instead of putting
them in httpdocs/files/domx, I'm putting them at httpdocs/domx,
just removing the 'files' folder to shorten the path a bit more.
So, regardless of whether the domain is in a dev state:
without having to change the system when I go from dev to live.
However, civicrm folder is still visible, as are some theme folders.
Does this make sense? Is close enough to what you're suggesting?
File path setup
Hi,
Yeah, that's pretty much what I do. I have a slight aversion to adding extra files into the Drupal root directory - mainly for the sake of tidyness (but I guess it's OK as long as you upgrade with a sync and not a delete-and-replace). It might get a bit messy when you have 20 or 30 Drupal sites!
I'm not familiar with CiviCRM, but it sounds like it's doing something similar to the themes - i.e. it uses its own equivalent of path_to_theme which gives you a filepath like 'sites/example.com/themes/mytheme/' so I guess there's not a lot you can do about that. Again, I use symlinks to point a site folder for my dev site to my prod site folder, so that all themes, modules and files get picked up from the same place. e.g:
/sites/example1.com/settings.php <- live prod server settings
/sites/example1.com/files/
/sites/example1.com/themes/
/sites/example1.com/modules/
/sites/example1.local/settings.php <- local dev server settings
/sites/example1.local/files <- symlink to ../example1.com/files/
/sites/example1.local/themes <- symlink to ../example1.com/themes/
/sites/example1.local/modules <- symlink to ../example1.com/modules/
Anyway, it sounds like you have things working OK...