diff --git a/include/class.misc.php b/include/class.misc.php
index b92909caac5f4f80bae768d9acf812fce5fb4c41..d49970e9f9ca8a92d5e16e29c146f329ad7bda60 100644
--- a/include/class.misc.php
+++ b/include/class.misc.php
@@ -141,11 +141,18 @@ class Misc {
 
     /* static */
     function siteRootPath($main_inc_path) {
+        if (!$_SERVER['DOCUMENT_ROOT'])
+            // Probably run from the command-line
+            return './';
         $root = str_replace('\\', '/', $main_inc_path);
         $root2 = str_replace('\\','/', $_SERVER['DOCUMENT_ROOT']);
         $path = '';
         while (strpos($_SERVER['DOCUMENT_ROOT'], $root) === false) {
             $lastslash = strrpos($root, '/');
+            if ($lastslash === false)
+                // Unable to find any commonality between $root and
+                // DOCUMENT_ROOT
+                return './';
             $path = substr($root, $lastslash) . $path;
             $root = substr($root, 0, $lastslash);
         }