Jump to:

22977 Posts in 11806 Topics by 2826 members

General Questions

SilverStripe Forums » General Questions » Multiple sites on a Windows server

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 382 Views
  • simples
    Avatar
    Community Member
    76 Posts

    Multiple sites on a Windows server Link to this post

    Hi,

    I am creating a number of community web sites for different parts of the country. These sites will be served from a Windows server. I want to avoid the management headache of having to update the codebase in each site when I add a feature or make a correction.

    The following describes what I am currently doing.

    I have created a file called config.php which sits in the root folder along with index.php and .htaccess. In this file I have placed the following code.

    <?php
    global $site_name,$site_description,$site_email,$site_database,$site_url;
    $site_name='xxxx';
    $site_description='xxxxxxxxxxxxxxxxxx';
    $site_email='xxxxxxxxxxxx';
    $site_database='xxxxxxx';
    $site_url='xxxxxxxxxxxxxxx';
    ?>

    I then add an include statement to this file in mysite/_config.php and any other file which needs access to these variables. For example I include it in a standalone file called query_database.php whose purpose is to retrieve data when it is called using Ajax from a Javascript file.

    I plan to update the codebase in each web site through running robocopy overnight to catch the changes made to the master web site during the day.

    No doubt there are better ways of doing things. If anyone has any suggestions, I would be interested to see them.

    Thanks.

  • simples
    Avatar
    Community Member
    76 Posts

    Re: Multiple sites on a Windows server Link to this post

    No suggestions?

    That is a pity because sapphire and cms are big folders to copy to all subsites whenever a change is made during the course of development.

    Please note that I have abandoned attempts to implement updates in a way which avoids changes being made to these system folders. I found that in certain circumstances that this was too challenging. The codebase is based on Version 2.4 and I will not be upgrading this installation to a newer version of the codebase.

    Please also note that I am running a Windows server.

  • Sean
    Avatar
    Forum Moderator
    921 Posts

    Re: Multiple sites on a Windows server Link to this post

    Have you tried using symlinks for the common dirs? Windows supports them, although I haven't tested: http://en.wikipedia.org/wiki/NTFS_symbolic_link

  • simples
    Avatar
    Community Member
    76 Posts

    Re: Multiple sites on a Windows server Link to this post

    Hi Sean,

    Thank you for this. I should have mentioned that I am using Windows 2003 but your helpful suggestion pointed me to

    www.rekenwonder.com/linkmagic.htm.

    I plan to try this later today.

  • simples
    Avatar
    Community Member
    76 Posts

    Re: Multiple sites on a Windows server Link to this post

    Further to my last post, in the end I created a PHP script which uses exec to run linkd.exe which comes free as part of the Windows Resource Kit Tools.

    I run this script whenever I need to refresh the links. Obviously any change made to the target directories and files automatically appear in each site without the need to run this script. This script only needs to be edited and rerun when a new site is added or a directory or file is added to the common target.

    There is bound to be loads of things wrong with this script but hopefully it gives an idea of what on first impressions appears to work for me. No doubt in days to come changes will be made to this script to resolve issues and make it work better. This all assumes that there is not a much simpler solution out there which I have overlooked.

    The script is shown below.

    <?php
    error_reporting(E_ALL);
    ini_set('display_errors','On');
    ?>
    <?php
    // ----
    // Sets inputs
    // ----
    $directories=array(
    'admin',
    'cms',
    'images',
    'module_calendar',
    'module_contactform',
    'module_cssmenu',
    'module_homepreviews',
    'module_localimages',
    'module_login',
    'module_my',
    'module_savechecks',
    'module_servervariables',
    'module_sitesearch',
    'module_slideshow',
    'mysite',
    'sapphire',
    'themes',
    );
    $files=array(
    'robots.txt',
    '.htaccess',
    'favicon.ico',
    );
    $sites=array(
    'totnes',
    'buckfastleigh',
    'ashburton',
    'newtonabbot',
    );
    // ----
    $results=array();
    foreach($sites as $site){
    if(!file_exists("d:/vhosts/$site"))mkdir("d:/vhosts/$site",0777);
    foreach($directories as $directory){
    $results[]=$site;
    $results[]=_unlink("d:/vhosts/$site/$directory");
    $results[]=_link("D:/vhosts/links/silverstripe/$directory","d:/vhosts/$site/$directory");
    $results[]=_list("d:/vhosts/$site/$directory");
    }
    foreach($files as $file){
    $results[]=$site;
    $results[]=_link("D:/vhosts/links/silverstripe/$file","d:/vhosts/$site/$file");
    }
    }
    /* debug */echo "<pre>";print_r("Variable=<strong>\$results</strong> Value=");print_r($results);echo "</pre>";
    ?>

    <?php
    function _link( $target, $link ) {
    if ($_SERVER['WINDIR'] || $_SERVER['windir']){
    if(is_dir($target)){
    // Links to directories in windows
    exec("linkd $link $target", $message, $val);
    $result=0==$val;
    $function=__FUNCTION__;
    return compact('result','function','message');
    }elseif(is_file($target)){
    // Hardlinks link to files in windows
    exec("fsutil hardlink create $link $target", $message, $val);
    $result=0==$val;
    $function=__FUNCTION__;
    return compact('result','function','message');
    }
    $result=false;
    $function=__FUNCTION__;
    $message='';
    return compact('result','function','message');
    }else{
    symlink($target,$link);
    }
    }

    function _unlink($link ){
    if ($_SERVER['WINDIR'] || $_SERVER['windir']){
    exec('linkd "' . $link . '" /D',$message,$val);
    $result=0==$val;
    $function=__FUNCTION__;
    return compact('result','function','message');
    } else {
    unlink($link);
    }
    }

    function _list($link){
    if ($_SERVER['WINDIR'] || $_SERVER['windir']){
    exec('linkd "' . $link . '"',$message,$val);
    $result=0==$val;
    $function=__FUNCTION__;
    return compact('result','function','message');
    }
    }

    ?>

    382 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.