diff --git a/apps/calendar/ajax/import/import.php b/apps/calendar/ajax/import/import.php
index 96d7af4834108d06f89f981bd26483ae4da82deb..c0797f6e425524124ff91a96748c630e856dbb65 100644
--- a/apps/calendar/ajax/import/import.php
+++ b/apps/calendar/ajax/import/import.php
@@ -11,7 +11,7 @@ require_once('../../../../lib/base.php');
 OC_JSON::checkLoggedIn();
 OC_Util::checkAppEnabled('calendar');
 $nl = "\n";
-$progressfile = OC::$SERVERROOT . '/apps/calendar/import_tmp/' . md5(session_id()) . '.txt';
+$progressfile = OC::$APPSROOT . '/apps/calendar/import_tmp/' . md5(session_id()) . '.txt';
 if(is_writable('import_tmp/')){
 	$progressfopen = fopen($progressfile, 'w');
 	fwrite($progressfopen, '10');
@@ -117,4 +117,4 @@ sleep(3);
 if(is_writable('import_tmp/')){
 	unlink($progressfile);
 }
-OC_JSON::success();
\ No newline at end of file
+OC_JSON::success();
diff --git a/apps/calendar/caldav.php b/apps/calendar/caldav.php
index db0b35da118f668626afec7a5cb43c080da4d88a..e0925c54ee714055506ee5241145d1bfcb1497bc 100644
--- a/apps/calendar/caldav.php
+++ b/apps/calendar/caldav.php
@@ -25,7 +25,7 @@ $nodes = array(
 
 // Fire up server
 $server = new Sabre_DAV_Server($nodes);
-$server->setBaseUri(OC::$WEBROOT.'/apps/calendar/caldav.php');
+$server->setBaseUri(OC::$APPSROOT.'/apps/calendar/caldav.php');
 // Add plugins
 $server->addPlugin(new Sabre_DAV_Auth_Plugin($authBackend,'ownCloud'));
 $server->addPlugin(new Sabre_CalDAV_Plugin());
diff --git a/apps/contacts/carddav.php b/apps/contacts/carddav.php
index a2bf492e2062643b00c474123505ddd0651a0fa5..c09ff80b99c632d4f1831a745c027140c2506879 100644
--- a/apps/contacts/carddav.php
+++ b/apps/contacts/carddav.php
@@ -39,7 +39,7 @@ $nodes = array(
 
 // Fire up server
 $server = new Sabre_DAV_Server($nodes);
-$server->setBaseUri(OC::$WEBROOT.'/apps/contacts/carddav.php');
+$server->setBaseUri(OC::$APPSROOT.'/apps/contacts/carddav.php');
 // Add plugins
 $server->addPlugin(new Sabre_DAV_Auth_Plugin($authBackend,'ownCloud'));
 $server->addPlugin(new Sabre_CardDAV_Plugin());
diff --git a/apps/remoteStorage/WebDAV.php b/apps/remoteStorage/WebDAV.php
index cad465181a985488f5a70369f673e06c39b3988b..3a463a21a5c0b94016e17b4349fa40cbfcc02f9d 100644
--- a/apps/remoteStorage/WebDAV.php
+++ b/apps/remoteStorage/WebDAV.php
@@ -66,7 +66,7 @@ if(count($pathParts) >= 3 && $pathParts[0] == '') {
 	$server = new Sabre_DAV_Server($publicDir);
 
 	// Path to our script
-	$server->setBaseUri(OC::$WEBROOT."/apps/remoteStorage/WebDAV.php/$ownCloudUser");
+	$server->setBaseUri(OC::$APPSROOT."/apps/remoteStorage/WebDAV.php/$ownCloudUser");
 
 	// Auth backend
 	$authBackend = new OC_Connector_Sabre_Auth_ro_oauth(
diff --git a/lib/app.php b/lib/app.php
index 1879a89cee34d6228ad938dd0b65455d825f99ce..696b35485bd75c891423bcfbe0d89572caf8d361 100644
--- a/lib/app.php
+++ b/lib/app.php
@@ -58,8 +58,8 @@ class OC_App{
 		$apps = OC_Appconfig::getApps();
 		foreach( $apps as $app ){
 			if( self::isEnabled( $app )){
-				if(is_file(OC::$SERVERROOT.'/apps/'.$app.'/appinfo/app.php')){
-					require( 'apps/'.$app.'/appinfo/app.php' );
+				if(is_file(OC::$APPSROOT.'/apps/'.$app.'/appinfo/app.php')){
+					require( $app.'/appinfo/app.php' );
 				}
 			}
 		}
@@ -268,7 +268,7 @@ class OC_App{
 		if(is_file($appid)){
 			$file=$appid;
 		}else{
-			$file=OC::$SERVERROOT.'/apps/'.$appid.'/appinfo/info.xml';
+			$file=OC::$APPSROOT.'/apps/'.$appid.'/appinfo/info.xml';
 			if(!is_file($file)){
 				return array();
 			}
@@ -363,9 +363,9 @@ class OC_App{
 	 */
 	public static function getAllApps(){
 		$apps=array();
-		$dh=opendir(OC::$SERVERROOT.'/apps');
+		$dh=opendir(OC::$APPSROOT.'/apps');
 		while($file=readdir($dh)){
-			if(is_file(OC::$SERVERROOT.'/apps/'.$file.'/appinfo/app.php')){
+			if(is_file(OC::$APPSROOT.'/apps/'.$file.'/appinfo/app.php')){
 				$apps[]=$file;
 			}
 		}
@@ -396,11 +396,11 @@ class OC_App{
 	 * @param string appid
 	 */
 	public static function updateApp($appid){
-		if(file_exists(OC::$SERVERROOT.'/apps/'.$appid.'/appinfo/database.xml')){
-			OC_DB::updateDbFromStructure(OC::$SERVERROOT.'/apps/'.$appid.'/appinfo/database.xml');
+		if(file_exists(OC::$APPSROOT.'/apps/'.$appid.'/appinfo/database.xml')){
+			OC_DB::updateDbFromStructure(OC::$APPSROOT.'/apps/'.$appid.'/appinfo/database.xml');
 		}
-		if(file_exists(OC::$SERVERROOT.'/apps/'.$appid.'/appinfo/update.php')){
-			include OC::$SERVERROOT.'/apps/'.$appid.'/appinfo/update.php';
+		if(file_exists(OC::$APPSROOT.'/apps/'.$appid.'/appinfo/update.php')){
+			include OC::$APPSROOT.'/apps/'.$appid.'/appinfo/update.php';
 		}
 	}
 
diff --git a/lib/base.php b/lib/base.php
index ee1a86399ac10b70c5b84f5ab51f1572b7d4e244..32dcfd7825825959446e6f239e13c2699619c0eb 100644
--- a/lib/base.php
+++ b/lib/base.php
@@ -62,6 +62,14 @@ class OC{
 	 * the root path of the 3rdparty folder for http requests (e.g. owncloud/3rdparty)
 	 */
 	public static $THIRDPARTYWEBROOT = '';
+        /**
+         * The installation path of the apps folder on the server (e.g. /srv/http/owncloud)
+         */
+        public static $APPSROOT = '';
+        /**
+         * the root path of the apps folder for http requests (e.g. owncloud)
+         */
+        public static $APPSWEBROOT = '';
 
 	/**
 	 * SPL autoload
@@ -179,9 +187,26 @@ class OC{
 			exit;
 		}
 
+                // search the apps folder
+                if(file_exists(OC::$SERVERROOT.'/apps')){
+                        OC::$APPSROOT=OC::$SERVERROOT;
+                        OC::$APPSWEBROOT=OC::$WEBROOT;
+                }elseif(file_exists(OC::$SERVERROOT.'/../apps')){
+                        $url_tmp=explode('/',OC::$WEBROOT);
+                        $length=count($url_tmp);
+                        unset($url_tmp[$length-1]);
+                        OC::$APPSWEBROOT=implode('/',$url_tmp);
+                        $root_tmp=explode('/',OC::$SERVERROOT);
+                        $length=count($root_tmp);
+                        unset($root_tmp[$length-1]);
+                        OC::$APPSROOT=implode('/',$root_tmp);
+                }else{
+                        echo("apps directory not found! Please put the ownCloud apps folder in the ownCloud folder or the folder above. You can also configure the location in the config.php file.");
+                        exit;
+                }
 
 		// set the right include path
-		set_include_path(OC::$SERVERROOT.'/lib'.PATH_SEPARATOR.OC::$SERVERROOT.'/config'.PATH_SEPARATOR.OC::$THIRDPARTYROOT.'/3rdparty'.PATH_SEPARATOR.get_include_path().PATH_SEPARATOR.OC::$SERVERROOT);
+		set_include_path(OC::$SERVERROOT.'/lib'.PATH_SEPARATOR.OC::$SERVERROOT.'/config'.PATH_SEPARATOR.OC::$THIRDPARTYROOT.'/3rdparty'.PATH_SEPARATOR.OC::$APPSROOT.PATH_SEPARATOR.OC::$APPSROOT.'/apps'.PATH_SEPARATOR.get_include_path().PATH_SEPARATOR.OC::$SERVERROOT);
 
 		// Redirect to installer if not installed
 		if (!OC_Config::getValue('installed', false) && OC::$SUBURI != '/index.php') {
diff --git a/lib/helper.php b/lib/helper.php
index 8cf94f81b0bdbc7eabdf8086cb6a04cf33e12e76..60af4e376b16d4ef94d86ef2d282b5d63e01ae7c 100644
--- a/lib/helper.php
+++ b/lib/helper.php
@@ -39,8 +39,8 @@ class OC_Helper {
 		if( $app != '' ){
 			$app .= '/';
 			// Check if the app is in the app folder
-			if( file_exists( OC::$SERVERROOT . '/apps/'. $app.$file )){
-				$urlLinkTo =  OC::$WEBROOT . '/apps/' . $app . $file;
+			if( file_exists( OC::$APPSROOT . '/apps/'. $app.$file )){
+				$urlLinkTo =  OC::$APPSWEBROOT . '/apps/' . $app . $file;
 			}
 			else{
 				$urlLinkTo =  OC::$WEBROOT . '/' . $app . $file;
@@ -89,8 +89,8 @@ class OC_Helper {
                 // Check if the app is in the app folder
                 if( file_exists( OC::$SERVERROOT."/themes/$theme/apps/$app/img/$image" )){
                         return OC::$WEBROOT."/themes/$theme/apps/$app/img/$image";
-                }elseif( file_exists( OC::$SERVERROOT."/apps/$app/img/$image" )){
-                        return OC::$WEBROOT."/apps/$app/img/$image";
+                }elseif( file_exists( OC::$APPSROOT."/apps/$app/img/$image" )){
+                        return OC::$APPSWEBROOT."/apps/$app/img/$image";
                 }elseif( !empty( $app ) and file_exists( OC::$SERVERROOT."/themes/$theme/$app/img/$image" )){
                         return OC::$WEBROOT."/themes/$theme/$app/img/$image";
                 }elseif( !empty( $app ) and file_exists( OC::$SERVERROOT."/$app/img/$image" )){
diff --git a/lib/installer.php b/lib/installer.php
index b2f817e702f306e8e05518a9bf38a1cb5d50870c..2cc7555f0d623777069635baa0000725e7b37549 100644
--- a/lib/installer.php
+++ b/lib/installer.php
@@ -103,7 +103,7 @@ class OC_Installer{
 			return false;
 		}
 		$info=OC_App::getAppInfo($extractDir.'/appinfo/info.xml');
-		$basedir=OC::$SERVERROOT.'/apps/'.$info['id'];
+		$basedir=OC::$APPSROOT.'/apps/'.$info['id'];
 		
 		//check if an app with the same id is already installed
 		if(self::isInstalled( $info['id'] )){
@@ -244,10 +244,10 @@ class OC_Installer{
 	 * If $enabled is false, apps are installed as disabled.
 	 */
 	public static function installShippedApps(){
-		$dir = opendir( OC::$SERVERROOT."/apps" );
+		$dir = opendir( OC::$APPSROOT."/apps" );
 		while( false !== ( $filename = readdir( $dir ))){
-			if( substr( $filename, 0, 1 ) != '.' and is_dir(OC::$SERVERROOT."/apps/$filename") ){
-				if( file_exists( OC::$SERVERROOT."/apps/$filename/appinfo/app.php" )){
+			if( substr( $filename, 0, 1 ) != '.' and is_dir(OC::$APPSROOT."/apps/$filename") ){
+				if( file_exists( OC::$APPSROOT."/apps/$filename/appinfo/app.php" )){
 					if(!OC_Installer::isInstalled($filename)){
 						$info = OC_Installer::installShippedApp($filename);
 						$enabled = isset($info['default_enable']);
@@ -270,15 +270,15 @@ class OC_Installer{
 	 */
 	public static function installShippedApp($app){
 		//install the database
-		if(is_file(OC::$SERVERROOT."/apps/$app/appinfo/database.xml")){
-			OC_DB::createDbFromStructure(OC::$SERVERROOT."/apps/$app/appinfo/database.xml");
+		if(is_file(OC::$APPSROOT."/apps/$app/appinfo/database.xml")){
+			OC_DB::createDbFromStructure(OC::$APPSROOT."/apps/$app/appinfo/database.xml");
 		}
 
 		//run appinfo/install.php
-		if(is_file(OC::$SERVERROOT."/apps/$app/appinfo/install.php")){
-			include(OC::$SERVERROOT."/apps/$app/appinfo/install.php");
+		if(is_file(OC::$APPSROOT."/apps/$app/appinfo/install.php")){
+			include(OC::$APPSROOT."/apps/$app/appinfo/install.php");
 		}
-		$info=OC_App::getAppInfo(OC::$SERVERROOT."/apps/$app/appinfo/info.xml");
+		$info=OC_App::getAppInfo(OC::$APPSROOT."/apps/$app/appinfo/info.xml");
 		OC_Appconfig::setValue($app,'installed_version',$info['version']);
 		return $info;
 	}
diff --git a/lib/l10n.php b/lib/l10n.php
index a5544eb3a2766c95e8aaed053ce05e946f04495c..636326f9864a84a4b3b718c09cf3ec4bb684eeb1 100644
--- a/lib/l10n.php
+++ b/lib/l10n.php
@@ -243,8 +243,8 @@ class OC_L10N{
 		$i18ndir = OC::$SERVERROOT.'/core/l10n/';
 		if($app != ''){
 			// Check if the app is in the app folder
-			if(file_exists(OC::$SERVERROOT.'/apps/'.$app.'/l10n/')){
-				$i18ndir = OC::$SERVERROOT.'/apps/'.$app.'/l10n/';
+			if(file_exists(OC::$APPSROOT.'/apps/'.$app.'/l10n/')){
+				$i18ndir = OC::$APPSROOT.'/apps/'.$app.'/l10n/';
 			}
 			else{
 				$i18ndir = OC::$SERVERROOT.'/'.$app.'/l10n/';
diff --git a/lib/template.php b/lib/template.php
index 5fe2eb7d6c7b320e7ec5e187c8130151a1171e6d..148e400d4e821bdeb86ec5c43a3c0b3360d5bc26 100644
--- a/lib/template.php
+++ b/lib/template.php
@@ -170,39 +170,39 @@ class OC_Template{
 
 		// Check if it is a app template or not.
 		if( $app != "" ){
-			// Check if the app is in the app folder or in the root
-			if( file_exists( OC::$SERVERROOT."/apps/$app/templates/" )){
-				// Check if the template is overwritten by the selected theme
-				if( file_exists( OC::$SERVERROOT."/themes/$theme/apps/$app/templates/"."$name$fext.php" )){
-					$template = OC::$SERVERROOT."/themes/$theme/apps/$app/templates/"."$name$fext.php";
-					$path = OC::$SERVERROOT."/themes/$theme/apps/$app/templates/";
-				}elseif( file_exists( OC::$SERVERROOT."/themes/$theme/apps/$app/templates/"."$name.php" )){
-					$template = OC::$SERVERROOT."/themes/$theme/apps/$app/templates/"."$name.php";
-					$path = OC::$SERVERROOT."/themes/$theme/apps/$app/templates/";
-				}elseif( OC::$SERVERROOT."/apps/$app/templates/"."$name$fext.php" ){
-					$template = OC::$SERVERROOT."/apps/$app/templates/"."$name$fext.php";
-					$path = OC::$SERVERROOT."/apps/$app/templates/";
-				}else{
-					$template = OC::$SERVERROOT."/apps/$app/templates/"."$name.php";
-					$path = OC::$SERVERROOT."/apps/$app/templates/";
-				}
-			}else{
-				// Check if the template is overwritten by the selected theme
-				if( file_exists( OC::$SERVERROOT."/themes/$theme/$app/templates/"."$name$fext.php" )){
-					$template = OC::$SERVERROOT."/themes/$theme/$app/templates/"."$name$fext.php";
-					$path = OC::$SERVERROOT."/themes/$theme/$app/templates/";
-				}elseif( file_exists( OC::$SERVERROOT."/themes/$theme/$app/templates/"."$name.php" )){
-					$template = OC::$SERVERROOT."/themes/$theme/$app/templates/"."$name.php";
-					$path = OC::$SERVERROOT."/themes/$theme/$app/templates/";
-				}elseif( file_exists( OC::$SERVERROOT."/$app/templates/"."$name$fext.php" )){
-					$template = OC::$SERVERROOT."/$app/templates/"."$name$fext.php";
-					$path = OC::$SERVERROOT."/$app/templates/";
-				}else{
-					$template = OC::$SERVERROOT."/$app/templates/"."$name.php";
-					$path = OC::$SERVERROOT."/$app/templates/";
-				}
-
-			}
+	                        // Check if the app is in the app folder or in the root
+                        if( file_exists( OC::$APPSROOT."/apps/$app/templates/" )){
+                                // Check if the template is overwritten by the selected theme
+                                if( file_exists( OC::$SERVERROOT."/themes/$theme/apps/$app/templates/"."$name$fext.php" )){
+                                        $template = OC::$SERVERROOT."/themes/$theme/apps/$app/templates/"."$name$fext.php";
+                                        $path = OC::$SERVERROOT."/themes/$theme/apps/$app/templates/";
+                                }elseif( file_exists( OC::$SERVERROOT."/themes/$theme/apps/$app/templates/"."$name.php" )){
+                                        $template = OC::$SERVERROOT."/themes/$theme/apps/$app/templates/"."$name.php";
+                                        $path = OC::$SERVERROOT."/themes/$theme/apps/$app/templates/";
+                                }elseif( OC::$APPSROOT."/apps/$app/templates/"."$name$fext.php" ){
+                                        $template = OC::$APPSROOT."/apps/$app/templates/"."$name$fext.php";
+                                        $path = OC::$APPSROOT."/apps/$app/templates/";
+                                }else{
+                                        $template = OC::$APPSROOT."/apps/$app/templates/"."$name.php";
+                                        $path = OC::$APPSROOT."/apps/$app/templates/";
+                                }
+                        }else{
+                                // Check if the template is overwritten by the selected theme
+                                if( file_exists( OC::$SERVERROOT."/themes/$theme/$app/templates/"."$name$fext.php" )){
+                                        $template = OC::$SERVERROOT."/themes/$theme/$app/templates/"."$name$fext.php";
+                                        $path = OC::$SERVERROOT."/themes/$theme/$app/templates/";
+                                }elseif( file_exists( OC::$SERVERROOT."/themes/$theme/$app/templates/"."$name.php" )){
+                                        $template = OC::$SERVERROOT."/themes/$theme/$app/templates/"."$name.php";
+                                        $path = OC::$SERVERROOT."/themes/$theme/$app/templates/";
+                                }elseif( file_exists( OC::$SERVERROOT."/$app/templates/"."$name$fext.php" )){
+                                        $template = OC::$SERVERROOT."/$app/templates/"."$name$fext.php";
+                                        $path = OC::$SERVERROOT."/$app/templates/";
+                                }else{
+                                        $template = OC::$SERVERROOT."/$app/templates/"."$name.php";
+                                        $path = OC::$SERVERROOT."/$app/templates/";
+                                }
+
+                        }	
 		}else{
 			// Check if the template is overwritten by the selected theme
 			if( file_exists( OC::$SERVERROOT."/themes/$theme/core/templates/"."$name$fext.php" )){
@@ -357,10 +357,10 @@ class OC_Template{
 					$page->append( "jsfiles", OC::$WEBROOT."/themes/$theme/apps/$script.js" );
 
 				// Is it part of an app?
-				}elseif(is_file(OC::$SERVERROOT."/apps/$script$fext.js" )){
-					$page->append( "jsfiles", OC::$WEBROOT."/apps/$script$fext.js" );
-				}elseif(is_file(OC::$SERVERROOT."/apps/$script.js" )){
-					$page->append( "jsfiles", OC::$WEBROOT."/apps/$script.js" );
+				}elseif(is_file(OC::$APPSROOT."/apps/$script$fext.js" )){
+					$page->append( "jsfiles", OC::$APPSWEBROOT."/apps/$script$fext.js" );
+				}elseif(is_file(OC::$APPSROOT."/apps/$script.js" )){
+					$page->append( "jsfiles", OC::$APPSWEBROOT."/apps/$script.js" );
 
 				// Is it in the owncloud root but overwritten by the theme?
 				}elseif(is_file(OC::$SERVERROOT."/themes/$theme/$script$fext.js" )){
@@ -394,10 +394,10 @@ class OC_Template{
 				if(is_file(OC::$THIRDPARTYROOT."/$style.css" )){
 					$page->append( "cssfiles", OC::$THIRDPARTYWEBROOT."/$style.css" );
 				// or in apps?
-				}elseif(is_file(OC::$SERVERROOT."/apps/$style$fext.css" )){
-					$page->append( "cssfiles", OC::$WEBROOT."/apps/$style$fext.css" );
-				}elseif(is_file(OC::$SERVERROOT."/apps/$style.css" )){
-					$page->append( "cssfiles", OC::$WEBROOT."/apps/$style.css" );
+				}elseif(is_file(OC::$APPSROOT."/apps/$style$fext.css" )){
+					$page->append( "cssfiles", OC::$APPSWEBROOT."/apps/$style$fext.css" );
+				}elseif(is_file(OC::$APPSROOT."/apps/$style.css" )){
+					$page->append( "cssfiles", OC::$APPSWEBROOT."/apps/$style.css" );
 				// or in the owncloud root?
 				}elseif(is_file(OC::$SERVERROOT."/$style$fext.css" )){
 					$page->append( "cssfiles", OC::$WEBROOT."/$style$fext.css" );