From add6d2b72611506f3d84ec56b375588f0182896e Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 3 Jul 2023 21:40:36 +0200 Subject: [PATCH] [ticket/17053] Add simple check for writable cache directory PHPBB3-17053 --- phpBB/common.php | 8 ++++++++ phpBB/phpbb/di/container_builder.php | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/phpBB/common.php b/phpBB/common.php index 3811cc9ef6..5518fb6f0a 100644 --- a/phpBB/common.php +++ b/phpBB/common.php @@ -114,6 +114,14 @@ $phpbb_class_loader_ext->register(); try { $phpbb_container_builder = new \phpbb\di\container_builder($phpbb_root_path, $phpEx); + + // Check that cache directory is writable before trying to build container + $cache_dir = $phpbb_container_builder->get_cache_dir(); + if (file_exists($cache_dir) && !is_writable($phpbb_container_builder->get_cache_dir())) + { + die('Unable to write to the cache directory path "' . $cache_dir . '". Ensure that the web server user can write to the cache folder.'); + } + $phpbb_container = $phpbb_container_builder->with_config($phpbb_config_php_file)->get_container(); } catch (InvalidArgumentException $e) diff --git a/phpBB/phpbb/di/container_builder.php b/phpBB/phpbb/di/container_builder.php index fe4127f30e..040a367f7c 100644 --- a/phpBB/phpbb/di/container_builder.php +++ b/phpBB/phpbb/di/container_builder.php @@ -420,7 +420,7 @@ class container_builder * * @return string Path to the cache directory. */ - protected function get_cache_dir() + public function get_cache_dir() { return $this->cache_dir ?: $this->phpbb_root_path . 'cache/' . $this->get_environment() . '/'; }