Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions /

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

Multiple sites on a Windows server


Reply


5 Posts   671 Views

Avatar
simples

Community Member, 77 Posts

3 July 2013 at 9:04am

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.

Avatar
simples

Community Member, 77 Posts

29 July 2013 at 8:17pm

Edited: 29/07/2013 8:18pm

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.

Avatar
Sean

Forum Moderator, 922 Posts

30 July 2013 at 12:11pm

Edited: 30/07/2013 12:14pm

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

Avatar
simples

Community Member, 77 Posts

30 July 2013 at 6:36pm

Edited: 30/07/2013 6:37pm

Hi Sean,

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

[url]www.rekenwonder.com/linkmagic.htm[/url].

I plan to try this later today.

Avatar
simples

Community Member, 77 Posts

7 August 2013 at 4:51am

Edited: 07/08/2013 7:04pm

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');
}
}

?>