views:

43

answers:

3

I've got a CakePHP install running six different web sites, each with their own webroot. All of the base code is the same (controllers, models, etc.), just the css, images, js and so forth are split into the separate webroots (app/webroot, app/webroot_second_site, app/webroot_third_site, etc.)

My question is: Is there a way to share common resources among the webroots? So we don't have six different copies of TinyMCE and jQuery cluttering up our project, and more importantly to me, so that we can make a change in a common CSS file instead of having to copy/paste a change across six different sites' folders?

If these sites were running on a Linux box, I think it could be fairly easily accomplished with a symlink from each of the webroots to a common folder higher up in the directory tree, but we're running Windows Server 2003 / IIS 6. Any suggestions?

A: 

You could make a static server. Add a DNS entry to something like static.yoursite.com. Link to those files from your other sites -- probably you could just modify the HTML helper so that it will automatically create links to the other domain.

This can help with performance, because you can run something like nginx to serve these static files. It will also parallelize the resource retrievals -- most browsers will allow 2 connections to a given server, so the static stuff competes with those connection resources that are needed by the dynamic stuff. In essence, the user will start 2 connections to your dynamic stuff as well as 2 connections to the static resources.

Works pretty well IME.

Travis Leleu
A: 

This will work. You will need to redefine the directories for a windows server, but you will understand it well enough.

First, put your APP and CAKE directories a level above the public_html.

/var/www/app
/var/www/cake

Make sure that the folder cake has all of the cake folders in it (cake, vendors, etc.) Point your sites to their public_html directories.

/var/www/html/site1
/var/www/html/site2

The webroot content will sit in each of the public_html directories. Now, modify your index.php file in each of the webroots to point to the same app:

if (!defined('ROOT')) {
    define('ROOT', DS.'var'.DS.'www'.DS.'app');
}

if (!defined('APP_DIR')) {
    define('APP_DIR',dirname('app'));
}

if (!defined('CAKE_CORE_INCLUDE_PATH')) {
    define('CAKE_CORE_INCLUDE_PATH', DS.'var'.DS.'www'.DS.'cake');
}

Make sure that rewrite is turned on of course. Then it will all run off the same code but use the webroot where the index.php is being served from.

cdburgess
Curtis, did this solution work for you?
cdburgess
+1  A: 

Turns out you can do directory symlinks in NTFS file systems. Or at least close enough for practical purposes. "NTFS Junctions" will work for what you want. Grab the Sysinternals "Junction" program for a simple command-line program to create/delete these junctions. Then you can link whatever common directories you need to a single master directory. For example, if you have

webroot1/ webroot2/ webroot3/

each with their own "js/" directory, then you could create

webroot_common/js/

and then symlink... er, "create junctions" to that new directory like so:

junction webroot1/js/common webroot_common/js
junction webroot2/js/common webroot_common/js
junction webroot3/js/common webroot_common/js

(yes, the "junction" program takes its inputs backwards from Linux "ln -s") Then you can put whatever common js files you need, like jQuery, in that common folder, and leave any site-specific js files in "webrootX/js".

Snelg

related questions