[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.

Access database (mdb file), format() function and ODBC/PHP

Can You tell a dif­fe­ren­ce between

SELECT *, format(Data_ur, "yyyy-mm-dd") AS Datur FROM Czlonkowie

and

SELECT *, format(Data_ur, 'yyyy-mm-dd') AS Datur FROM Czlonkowie

?

It turns out that when using ODBC to con­nect to Micro­soft Access data­ba­se (in an mdb file), one has to use sin­gle quotes when wri­ting func­tion para­me­ters. The first sta­te­ment runs fine from the Access itself, but when cal­led thro­ugh the ODBC (for instan­ce when using PHP and PDO) it returns emp­ty set (it doesn’t even throw an exception).

The second sta­te­ment (with sin­gle quotes) runs fine thro­ugh ODBC. Worth remembering.

[en] Accessing MSSQL database from Linux using nice GUI

Some­ti­mes Your custo­mer just has that blo­ody hosting with IIS and MSSQL data­ba­se inste­ad of good old Apache+MySQL. I used to use Sql­Bud­dy on Win­dows, but after swit­ching to Linux I had hard time fin­ding a nice GUI fron­tend to MSSQL (Sql­Bud­dy fails to work under Wine).

Along came JDBC 🙂

The­re­’s a real­ly nice uni­ver­sal JDBC GUI fron­tend cal­led Squ­ir­rel­SQL. Just down­lo­ad and java ‑jar installer.jar and select MSSQL plu­gin. Then down­lo­ad jTDS dri­ver and unzip the JAR some­whe­re. Run Squ­ir­rel SQL using its .sh script and double click „Micro­soft MSSQL Server JDBC dri­ver”. Add jtds‑v.e.r.jar to Extra Class Path and chan­ge Class Name to net.sourceforge.jtds.jdbc.Driver and Exam­ple URL to jdbc:jtds:sqlserver://<server_name>.

Then cre­ate new alias, test and… voila! 🙂

[en] Running CodeIgniter controller methods from external application

Gosh, this blog gets too tech­ni­cal 🙁 I guess I need to start wri­ting some kind of non-IT jour­nal here. You know, the teena­ge-pink-blog style 😉

Any­way, more for my own reference.

Code­Igni­ter is a nice and nonin­tru­si­ve PHP appli­ca­tion fra­me­work that I’ve grown to like and use it (also com­mer­cial­ly). The pro­blem is inte­gra­ting its MVC with exter­nal appli­ca­tions such as CMSes.

Here­’s a quick hack I’ve done to make this possible:

1. Cre­ate „exter­nal” sub­di­rec­to­ry under „sys­tem” direc­to­ry of Code­Igni­ter installation.
2. Pla­ce atta­ched files there.
3. Open „system/libraries/Loader.php” file and patch it like this: find line 681 and change

global $OUT;
$OUT->set_output(ob_get_contents());

to

global $OUT;
if (!isset($OUT)) $OUT = $GLOBALS['ci_external_out'];
$OUT->set_output(ob_get_contents());

4. For exam­ple of use, see atta­ched index.php file, basi­cal­ly to call a con­trol­ler method, just do this:

require_once 'ciexternal.php';
echo ci_external('controller', 'method');