[en] Installing SilverStripe on IIS server

UPDATE 2009-02-17: As Sigurd from SilverStripe team states in a comment, You shouldn’t need to follow my „howto” – at least if You’re using IIS 7. Since I wrote this „howto”, SilverStripe website has been improved to include installation instructions on IIS so please give it a try before proceeding with my old instructions.

1. Install ISAPI/Rewrite. I have no idea how to do it since it was already installed at my provider’s server, but there probably is a limited free version that is enough.
2. Download SilverStripe archive and extract it to Your server.
3. Go to Your server’s URL and fill in installer details as usual.
4. After rewritetest fails, create httpd.ini file in SilverStripe root directory and make its contents like that (what it basically does with ISAPI/Rewrite is to mimic Apache’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 proceed anyway” link and You should be redirected to an ugly looking „successfully installed” 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 „successfully installed” page and if it looks pretty now, You know You correctly did step 6.
8. Click „Click here to delete the install files.” link so You don’t have a security hole.
9. Now edit /sapphire/main.php file and at the very beginning add these lines:

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

10. Following are hacks I needed to add so i18n works on IIS. If You don’t use i18n, You’ll probably be fine without these hacks. This method is in sapphire/core/i18n.php file:

protected static function get_owner_module($name) {
if (substr($name,-3) == ‚.ss’) {
global $_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 {
global $_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 checking out this thread at SilverStripe forum where most of the above info is found.

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

Can You tell a difference 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 connect to Microsoft Access database (in an mdb file), one has to use single quotes when writing function parameters. The first statement runs fine from the Access itself, but when called through the ODBC (for instance when using PHP and PDO) it returns empty set (it doesn’t even throw an exception).

The second statement (with single quotes) runs fine through ODBC. Worth remembering.

[en] Accessing MSSQL database from Linux using nice GUI

Sometimes Your customer just has that bloody hosting with IIS and MSSQL database instead of good old Apache+MySQL. I used to use SqlBuddy on Windows, but after switching to Linux I had hard time finding a nice GUI frontend to MSSQL (SqlBuddy fails to work under Wine).

Along came JDBC 🙂

There’s a really nice universal JDBC GUI frontend called SquirrelSQL. Just download and java -jar installer.jar and select MSSQL plugin. Then download jTDS driver and unzip the JAR somewhere. Run Squirrel SQL using its .sh script and double click „Microsoft MSSQL Server JDBC driver”. Add jtds-v.e.r.jar to Extra Class Path and change Class Name to net.sourceforge.jtds.jdbc.Driver and Example URL to jdbc:jtds:sqlserver://<server_name>.

Then create new alias, test and… voila! 🙂

[en] Running CodeIgniter controller methods from external application

Gosh, this blog gets too technical 🙁 I guess I need to start writing some kind of non-IT journal here. You know, the teenage-pink-blog style 😉

Anyway, more for my own reference.

CodeIgniter is a nice and nonintrusive PHP application framework that I’ve grown to like and use it (also commercially). The problem is integrating its MVC with external applications such as CMSes.

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

1. Create „external” subdirectory under „system” directory of CodeIgniter installation.
2. Place attached 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 example of use, see attached index.php file, basically to call a controller method, just do this:

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