diff --git a/config/application.config.php b/config/application.config.php
index 2efe44d7c654c251eeed4e4c8232a1ad8bb1f5fe..0cdb7c948d1aaf39ffe7581a0d9d20098961d073 100644
--- a/config/application.config.php
+++ b/config/application.config.php
@@ -22,14 +22,18 @@ if ($localModules = getenv('VUFIND_LOCAL_MODULES')) {
 // Set up cache directory (be sure to keep separate cache for CLI vs. web and
 // to account for potentially variant environment settings):
 $baseDir = ($local = getenv('VUFIND_LOCAL_DIR')) ? $local : 'data';
+$cacheDir = $baseDir . '/cache';
+if (!is_dir($cacheDir)) {
+    mkdir($cacheDir);
+}
 if (PHP_SAPI == 'cli') {
-    $cacheDir = $baseDir . '/cache/cli';
+    $cacheDir .= '/cli';
     if (!is_dir($cacheDir)) {
         mkdir($cacheDir);
     }
     $cacheDir .= '/configs';
 } else {
-    $cacheDir = $baseDir . '/cache/configs';
+    $cacheDir .= '/configs';
 }
 if (!is_dir($cacheDir)) {
     mkdir($cacheDir);