diff --git a/apps/files/appinfo/update.php b/apps/files/appinfo/update.php
index 2691c05c3487a8843f6eff3cf7cf2e3626e0a447..ff1369bb1a556c53fc67b1bb4ec1185cea42300a 100644
--- a/apps/files/appinfo/update.php
+++ b/apps/files/appinfo/update.php
@@ -94,3 +94,12 @@ if ($installedVersion === '1.1.9' && (
 		}
 	}
 }
+
+/**
+ * migrate old constant DEBUG to new config value 'debug'
+ *
+ * TODO: remove this in ownCloud 8.3
+ */
+if(defined('DEBUG') && DEBUG === true) {
+	\OC::$server->getConfig()->setSystemValue('debug', true);
+}
diff --git a/apps/files/appinfo/version b/apps/files/appinfo/version
index 5ed5faa5f1627058b32f8822c9864eab7c233ea2..9ee1f786d50f8fe4a9efd3c4931f960ed5506431 100644
--- a/apps/files/appinfo/version
+++ b/apps/files/appinfo/version
@@ -1 +1 @@
-1.1.10
+1.1.11
diff --git a/config/config.sample.php b/config/config.sample.php
index 522cf02cebac26817c6aeecd83f83ece453ed130..234bf8e0fa3a690b00dd3b6edfef75f01b8b1fca 100644
--- a/config/config.sample.php
+++ b/config/config.sample.php
@@ -20,12 +20,6 @@
  *  * use RST syntax
  */
 
-/**
- * Only enable this for local development and not in production environments
- * This will disable the minifier and outputs some additional debug informations
- */
-define('DEBUG', true);
-
 $CONFIG = array(
 
 
@@ -1079,6 +1073,14 @@ $CONFIG = array(
  */
 'memcache.locking' => '\\OC\\Memcache\\Redis',
 
+/**
+ * Set this ownCloud instance to debugging mode
+ *
+ * Only enable this for local development and not in production environments
+ * This will disable the minifier and outputs some additional debug information
+ */
+'debug' => false,
+
 /**
  * This entry is just here to show a warning in case somebody copied the sample
  * configuration. DO NOT ADD THIS SWITCH TO YOUR CONFIGURATION!
diff --git a/core/js/config.php b/core/js/config.php
index 95dd7330287f0b87b0fa47af04dac3974389167a..21451bf91b006e5bc7b4baaa0069420fcb56f284 100644
--- a/core/js/config.php
+++ b/core/js/config.php
@@ -62,7 +62,7 @@ if ($defaultExpireDateEnabled) {
 $outgoingServer2serverShareEnabled = $config->getAppValue('files_sharing', 'outgoing_server2server_share_enabled', 'yes') === 'yes';
 
 $array = array(
-	"oc_debug" => (defined('DEBUG') && DEBUG) ? 'true' : 'false',
+	"oc_debug" => $config->getSystemValue('debug', false),
 	"oc_isadmin" => OC_User::isAdminUser(OC_User::getUser()) ? 'true' : 'false',
 	"oc_webroot" => "\"".OC::$WEBROOT."\"",
 	"oc_appswebroots" =>  str_replace('\\/', '/', json_encode($apps_paths)), // Ugly unescape slashes waiting for better solution
diff --git a/lib/base.php b/lib/base.php
index 2435661dfa6bb0921e802ea34c40a2caa4d67e5a..aceac2e53c3bfc50345973616af76f94af019be3 100644
--- a/lib/base.php
+++ b/lib/base.php
@@ -582,7 +582,7 @@ class OC {
 		if (!defined('PHPUNIT_RUN')) {
 			$logger = \OC::$server->getLogger();
 			OC\Log\ErrorHandler::setLogger($logger);
-			if (defined('DEBUG') and DEBUG) {
+			if (\OC::$server->getConfig()->getSystemValue('debug', false)) {
 				OC\Log\ErrorHandler::register(true);
 				set_exception_handler(array('OC_Template', 'printExceptionErrorPage'));
 			} else {
@@ -1040,7 +1040,7 @@ class OC {
 			return false;
 		}
 
-		if (defined("DEBUG") && DEBUG) {
+		if (\OC::$server->getConfig()->getSystemValue('debug', false)) {
 			\OCP\Util::writeLog('core', 'Trying to login from cookie', \OCP\Util::DEBUG);
 		}
 
@@ -1093,11 +1093,12 @@ class OC {
 
 			self::cleanupLoginTokens($userId);
 			if (!empty($_POST["remember_login"])) {
-				if (defined("DEBUG") && DEBUG) {
+				$config = self::$server->getConfig();
+				if ($config->getSystemValue('debug', false)) {
 					self::$server->getLogger()->debug('Setting remember login to cookie', array('app' => 'core'));
 				}
 				$token = \OC::$server->getSecureRandom()->getMediumStrengthGenerator()->generate(32);
-				self::$server->getConfig()->setUserValue($userId, 'login_token', $token, time());
+				$config->setUserValue($userId, 'login_token', $token, time());
 				OC_User::setMagicInCookie($userId, $token);
 			} else {
 				OC_User::unsetMagicInCookie();
diff --git a/lib/private/config.php b/lib/private/config.php
index 20ff02c1abfecd8c528600f7e000346c9a787689..3ad800a00bec7213dfc766ad9e716a1d1f98b625 100644
--- a/lib/private/config.php
+++ b/lib/private/config.php
@@ -47,8 +47,6 @@ class Config {
 	protected $configFilePath;
 	/** @var string */
 	protected $configFileName;
-	/** @var bool */
-	protected $debugMode;
 
 	/**
 	 * @param string $configDir Path to the config dir, needs to end with '/'
@@ -59,7 +57,6 @@ class Config {
 		$this->configFilePath = $this->configDir.$fileName;
 		$this->configFileName = $fileName;
 		$this->readData();
-		$this->debugMode = (defined('DEBUG') && DEBUG);
 	}
 
 	/**
@@ -225,9 +222,6 @@ class Config {
 	private function writeData() {
 		// Create a php file ...
 		$content = "<?php\n";
-		if ($this->debugMode) {
-			$content .= "define('DEBUG',true);\n";
-		}
 		$content .= '$CONFIG = ';
 		$content .= var_export($this->cache, true);
 		$content .= ";\n";
diff --git a/lib/private/server.php b/lib/private/server.php
index 92a671c721dd387b787e2b8e3e8655065ab8fbac..5a3a6328fae91d9a0d8c374120db475111f53509 100644
--- a/lib/private/server.php
+++ b/lib/private/server.php
@@ -329,14 +329,14 @@ class Server extends SimpleContainer implements IServerContainer {
 			);
 		});
 		$this->registerService('EventLogger', function (Server $c) {
-			if (defined('DEBUG') and DEBUG) {
+			if ($c->getSystemConfig()->getValue('debug', false)) {
 				return new EventLogger();
 			} else {
 				return new NullEventLogger();
 			}
 		});
-		$this->registerService('QueryLogger', function ($c) {
-			if (defined('DEBUG') and DEBUG) {
+		$this->registerService('QueryLogger', function (Server $c) {
+			if ($c->getSystemConfig()->getValue('debug', false)) {
 				return new QueryLogger();
 			} else {
 				return new NullQueryLogger();
diff --git a/lib/private/template.php b/lib/private/template.php
index e7acc778de343af6976ccd6c5969228b3421430b..920be71abbfac574773eadfdd46c2d79441c1808 100644
--- a/lib/private/template.php
+++ b/lib/private/template.php
@@ -233,7 +233,7 @@ class OC_Template extends \OC\Template\Base {
 		$content->assign('file', $exception->getFile());
 		$content->assign('line', $exception->getLine());
 		$content->assign('trace', $exception->getTraceAsString());
-		$content->assign('debugMode', defined('DEBUG') && DEBUG === true);
+		$content->assign('debugMode', \OC::$server->getSystemConfig()->getValue('debug', false));
 		$content->assign('remoteAddr', $request->getRemoteAddress());
 		$content->assign('requestID', $request->getId());
 		$content->printPage();