I currently have several sites all using the same CMS code base. They all share the same include paths for the CMS and library files, with each having an index, htaccess and config file.

As the these files are identical for each client, it would be easier for me to use the same for all clients.

I had an idea that I could set the client id inside either the virtual host. This would all work great if I had no other files which needed to be inside the domain folder (I could symlink the two folders, or set the documentroot to the base "public" directory for each domain)... but unfortunately there are data files that need to be in domain folder.

So, ideally, I would like a structure like so:


    .data files and folders (no index, htaccess file etc)
    .data folders and files (no index, htaccess file etc)

    index.php (which calls the cms bootstrap)

How can i configure it in such a way that the file structure cascades down (in some cases, i might want to place an index file in the default domain httpdocs folder).

Thanks. ps. couldn't decide on serverfault or stackoverflow

1 Answer 1


How much work you will have to do to make this happen will depend on the details and flexibility of your CMS' codebase.

When I make sites, I like to use the Apache SetEnv directive in each of my site's vhost files. E.g.

SetEnv BASECMS          /var/lib/basecms/
SetEnv SHAREDLIBS       /var/lib/sharedlibs/
SetEnv CLASSPATH        /source/site1/classes/
SetEnv VIEWPATH         /source/site1/views/
SetEnv CONFIGPATH       /source/site1/configs/
SetEnv _JSCRIPTS        /source/site1/www/_jscripts/
SetEnv _IMAGES          /source/site1/www/_images/
SetEnv _CSS             /source/site1/www/_css/

I can then reference these environment variables in my php code:

//[path definitions]
// php paths - all have trailing slashes
define('BASECMS',           $_SERVER['BASECMS']);       // in /var/lib/basecms
define('SHAREDLIBS',        $_SERVER['SHAREDLIBS']);    // in /var/lib/sharedlibs
define('CLASSPATH',         $_SERVER['CLASSPATH']); // in /source/site1...
define('VIEWPATH',          $_SERVER['VIEWPATH']);      // in /source/site1...
define('CONFIGPATH',        $_SERVER['CONFIGPATH']);    // in /source/site1...

FYI - these paths are outside each site's document root for security - the document root for each site is /source/site1/www/.

Thanks to passing all the site-specific vars from apache vhost (analogous to the "client id" you mentioned), my site's structural code (/var/lib/...) stays the same and will cascade down. Site-specific code is picked up via references to the /source/site1 paths.

To get around the issue of linking to shared files that are inside the docroot of each specific site, typically shared css/javascript/img files as when you said:

This would all work great if I had no other files which needed to be inside the domain folder... but unfortunately there are data files that need to be in domain folder.

I will make some more definitions, specifically for the stuff I need to have shared:

// js, css, image paths some unique to each site, some shared/library used by all
define('JSPATH',            $_SERVER['_JSCRIPTS']);
define('LIBRARYJSPATH',     JSPATH.'library');  // to be symlinked under docroot
define('SHAREDJSPATH',      JSPATH.'shared');   // to be symlinked under docroot
define('CSSPATH',           $_SERVER['_CSS']);
define('IMAGEPATH',         $_SERVER['_IMAGES']);

then I will make specific symlinks inside the docroot, back out to the shared locations:

ln -s /var/lib/libjs /source/site1/www/_jscripts/library 
ln -s /var/lib/basecms/jscripts /source/site1/www/_jscripts/shared

The end result is a directory structure accessible to my app that contains shared and site-specific code and assets.

tl;dr - yes, depending on your app's limitations you can use SetEnv in apache to let your app see both common and unique code, and use individual symlinks underneath docroot to 'merge' common and unique assets.

This topic is a favourite of mine - if you want to paste more specifics of your environment happy to get into specifics with you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.