diff --git a/lib/base.php b/lib/base.php
index baa384d102e625f26274427e2d2a11da2c10040f..de458cedb1e63a5ca717b4c66b553f40de63c6ce 100644
--- a/lib/base.php
+++ b/lib/base.php
@@ -225,9 +225,7 @@ class OC{
 				if (isset($_SERVER['SERVER_SOFTWARE']) && strstr($_SERVER['SERVER_SOFTWARE'], 'Apache')) {
 					if(!OC_Util::ishtaccessworking()) {
 						if(!file_exists(OC::$SERVERROOT.'/data/.htaccess')) {
-							$content = "deny from all\n";
-							$content.= "IndexIgnore *";
-							file_put_contents(OC_Config::getValue('datadirectory', OC::$SERVERROOT.'/data').'/.htaccess', $content);
+							OC_Setup::protectDataDirectory();
 						}
 					}
 				}		
diff --git a/lib/setup.php b/lib/setup.php
index 579a1b523ce4453ce9ae11207f3d1d8bfd366f54..1d3fbd1c8eab0958a4eab5d689dda94b1ccf631c 100644
--- a/lib/setup.php
+++ b/lib/setup.php
@@ -559,6 +559,10 @@ class OC_Setup {
 		$content.= "Options -Indexes\n";
 		@file_put_contents(OC::$SERVERROOT.'/.htaccess', $content); //supress errors in case we don't have permissions for it
 
+		self::protectDataDirectory();
+	}
+
+	public static function protectDataDirectory() {
 		$content = "deny from all\n";
 		$content.= "IndexIgnore *";
 		file_put_contents(OC_Config::getValue('datadirectory', OC::$SERVERROOT.'/data').'/.htaccess', $content);