[en] Installing SilverStripe on IIS server

UPDATE 2009-02-17: As Sigurd from Silver­Stri­pe team sta­tes in a com­ment, You sho­uld­n’t need to fol­low my „how­to” — at least if You’re using IIS 7. Sin­ce I wro­te this „how­to”, Silver­Stri­pe websi­te has been impro­ved to inc­lu­de instal­la­tion instruc­tions on IIS so ple­ase give it a try befo­re pro­ce­eding with my old instructions.

1. Install ISAPI/Rewrite. I have no idea how to do it sin­ce it was alre­ady instal­led at my pro­vi­de­r’s server, but the­re pro­ba­bly is a limi­ted free ver­sion that is enough.
2. Down­lo­ad Silver­Stri­pe archi­ve and extract it to Your server.
3. Go to Your serve­r’s URL and fill in instal­ler deta­ils as usual.
4. After rew­ri­te­test fails, cre­ate httpd.ini file in Silver­Stri­pe root direc­to­ry and make its con­tents like that (what it basi­cal­ly does with ISAPI/Rewrite is to mimic Apa­che­’s mod_rewrite):

[ISAPI_Rewrite] RewriteEngine On

RewriteCond URL (?!.*gif|.*jpg|.*png|.*swf|.*xml|.*css|.*flv|.*js|.*php).*
RewriteCond URL (?!.*\?).*
RewriteRule (.*) /sapphire/main.php\?url=$1 [I,L]

RewriteCond URL (?!.*gif|.*jpg|.*png|.*swf|.*xml|.*css|.*flv|.*js|.*php).*
RewriteCond URL .*\?.*
RewriteRule (.*)\?(.*) /sapphire/main.php\?url=$1&$2 [I,L]

5. Click „click here to pro­ce­ed any­way” link and You sho­uld be redi­rec­ted to an ugly looking „suc­cess­ful­ly instal­led” page.
6. Now edit /sapphire/core/control/Director.php file and change

$s = (isset($_SERVER[‘SSL’]) || isset($_SERVER[‘HTTPS’])) ? ‘s’ : ”;

line to

$s = (isset($_SERVER[‘SSL’]) || (isset($_SERVER[‘HTTPS’]) && $_SERVER[‘HTTPS’] == ‘on’)) ? ‘s’ : ”;

7. Refresh the „suc­cess­ful­ly instal­led” page and if it looks pret­ty now, You know You cor­rec­tly did step 6.
8. Click „Click here to dele­te the install files.” link so You don’t have a secu­ri­ty hole.
9. Now edit /sapphire/main.php file and at the very begin­ning add the­se lines:

if (!isset($_SERVER[‘REQUEST_URI’])) {
$_SERVER[‘REQUEST_URI’] = $_SERVER[‘SCRIPT_NAME’];
}

10. Fol­lo­wing are hacks I needed to add so i18n works on IIS. If You don’t use i18n, You’ll pro­ba­bly be fine witho­ut the­se hacks. This method is in sapphire/core/i18n.php file:

pro­tec­ted sta­tic func­tion get_owner_module($name) {
if (substr($name,-3) == ‘.ss’) {
glo­bal $_TEMPLATE_MANIFEST;
$path = current($_TEMPLATE_MANIFEST[substr($name,0,-3)]);
// hacks for IIS start –>
$path = str_replace(‘\sapphire/..’, ”, $path);
$path = str_replace(‘C:’, ”, $path);
$path = str_replace(‘\’, ‘/’, $path);
$bf = Director::baseFolder();
$bf = str_replace(‘C:’, ”, $bf);
$bf = str_replace(‘\’, ‘/’, $bf);
// – end hacks
ereg($bf . ‘/([^/]+)/’,$path,$module);
} else {
glo­bal $_CLASS_MANIFEST;
$path = $_CLASS_MANIFEST[$name];
// hacks for IIS start –>
$path = str_replace(‘\sapphire/..’, ”, $path);
$path = str_replace(‘C:’, ”, $path);
$path = str_replace(‘\’, ‘/’, $path);
$bf = Director::baseFolder();
$bf = str_replace(‘C:’, ”, $bf);
$bf = str_replace(‘\’, ‘/’, $bf);
// – end hacks
ereg($bf . ‘/([^/]+)/’,$path,$module);
}
return $module[1];
}

11. Enjoy 🙂
12. If You can’t enjoy for some reason, try chec­king out this thre­ad at Silver­Stri­pe forum whe­re most of the abo­ve info is found.