Monday, 10 November 2008

Install Silverstripe 'Subsites' module

The following steps worked for me when installing the Silverstripe Subsites module:

1. Create a directory in your root silverstripe installation. '~/Sites/silverstripe/subsites'

Download, and unzip the code into this directory. I deleted the 'trunk' directory to keep things tidy.

2. Ensure every folder in your silverstripe hierarchy has the user '_www' read/write access

3. There is a problem linking the Group table in the database, so for now comment it out in 'silverstripe/subsites/_config.php' so it looks like this:
<?php

/**
* The subsites module modifies the behaviour of the CMS - in the SiteTree and Group databases - to store information
* about a number of sub-sites, rather than a single site.
*/


Object::add_extension('SiteTree', 'SiteTreeSubsites');
// Hack - this ensures that the SiteTree defineMethods gets called before any of its subclasses...
new SiteTree();
Object::add_extension('ContentController', 'ControllerSubsites');
Object::add_extension('LeftAndMain', 'LeftAndMainSubsites');
Object::add_extension('LeftAndMain', 'ControllerSubsites');
//Object::add_extension('Group', 'GroupSubsites');
Object::add_extension('File', 'FileSubsites');

?>


Then visit http://localhost/silverstripe/db/build?flush=1 This will set up the initial database tables for the subsites module.


5. We need to manually modify the Group table using the following SQL. Note that 'Group' is a reserved keyword in mysql so make sure you wrap it in backquotes:

alter table `Group` add SubsiteID int(11) not null default 0;

6. We also need to manually insert the first 'Template' into the Subsite table:

insert into Subsite (ID, ClassName, Created, LastEdited, Subdomain, Title, Domain)
values ("", "Subsite_Template", NOW(), NOW(), "newsubdomain", "newtitle", "mysite.com");

7. Now you can uncomment your 'silverstripe/subsites/_config.php' file and add the following two lines so that it looks like this:

<?php

Object::add_extension('SiteTree', 'SiteTreeSubsites');
// Hack - this ensures that the SiteTree defineMethods gets called before any of its subclasses...
new SiteTree();
Object::add_extension('ContentController', 'ControllerSubsites');
Object::add_extension('LeftAndMain', 'LeftAndMainSubsites');
Object::add_extension('LeftAndMain', 'ControllerSubsites');
Object::add_extension('Group', 'GroupSubsites');
Object::add_extension('File', 'FileSubsites');

Director::addRules(100, array(
'admin/subsites/$Action/$ID/$OtherID' => 'SubsiteAdmin',
)
);
Object::addStaticVars( 'LeftAndMain', array( 'extra_menu_items' => array(
'Sub-sites' => array("intranets", "admin/subsites/", 'SubsiteAdmin')
)
)
);

?>


For good measure, visit http://localhost/silverstripe/?flush=1 to make sure any database changes have been picked up.

8. Then visit http://localhost/silverstripe/admin?flush=1 to reload your CMS.
You should now have the 'Sub-Sites' tab in the Silverstripe admin CMS along with a dropdown in the top right hand corner that allows you to select which subsite you are currently working on.

Documentation for this module is in alpha ;-) , so if anyone has any tips on refining these installation instructions please let me know.

9 comments:

Daniel said...

You are awesome. This is much-needed information. I was in the process of hacking through (and planning on making a write-up if I figured it out) when I found this. You have provided information I wouldn't have been able to find myself and thank you muchly...

Barry said...

No problem Daniel, glad I could help!

peter said...

Nice work Barry

Peter

faizan ahmad said...

Great help

Joni said...

This was great - it actually worked for me... mostly. I do have my subsite created, however the Subsites button on the top menu bar does not do anything. Would you have a clue as to what I may have done wrong? Otherwise, I am thrilled to have found instructions that I could actually understand and follow. Thanks so much!

Barry said...

Hmm... I'm not sure Joni. A point to note is that this article is now wildly out of date. The Subsite module should just work out of the box now.

If you wan't to contact me there's an email link on gingerleprechaun.com

ben.lopatin said...

Barry, how did you get URL requests to the subsite properly configured? I found the installation pretty straight forward, but have been banging my head against a wall trying to get Silverstripe to show a subsite when called from the given subsite.

tom said...

Not sure what this is supposed to do. Dropped the directory in place, renamed it, and both the management screen and user screens were blank.

Tried db/flush, no luck. Didn't create any new tables, despite following all your directions.

I'm on 4.2. Is this a problem? Multisite is critical, we'll have to find another system than Silverstrip if it is.

Barry said...

Hi Tom,

These instructions applied to a very old version of SS, when the subsites module was alpha, and are now obsolete. You can email me using me at keeny co uk.

*Comments for this post are now closed*