We are installing Blesta 4.0.0 and notice that during the installation process an alert was issued saying that our cache directory was not writable. This was strange to us because in our environment, the user who runs PHP has write access (we use suPHP for security reasons).
Upon closer look we notice that Blesta 4.0.0 does not ship with an empty cache directory (as defined by CACHEDIR). Rather, the code assumes that the cache directory already exists. You can see this below:
app/controllers/install.php
807 'cache_writable' => [
808 'message' => Language::_('SystemRequirements.!warning.cache_writable.recommended', true, CACHEDIR),
809 'req' => true,
810 'cur' => is_writable(CACHEDIR)
811 ], // To cache view files for performance
The PHP function is_writable does two things: checks if the user can write AND if the file exists. Since Blesta does not ship with an empty CACHEDIR (nor was anything mentioned to create one in the README), we get an error for no reason.
Below is a patch for a proposed fix. It checks to see if a file exists, if it does, then performs the is_writable test. Otherwise, attempt to create a directory and check if we can write to it The second test is probably pointless cause if you can create a directory you should be able to write to it, but edge cases can be tricky if parent folder has sticky bits enable, etc.
-Adam
diff --git a/app/controllers/install.php b/app/controllers/install.php
index a6c462e..414d3a8 100644
--- a/app/controllers/install.php
+++ b/app/controllers/install.php
@@ -807,7 +807,7 @@ class Install extends Controller
'cache_writable' => [
'message' => Language::_('SystemRequirements.!warning.cache_writable.recommended', true, CACHEDIR),
'req' => true,
- 'cur' => is_writable(CACHEDIR)
+ 'cur' => (file_exists(CACHEDIR)) ? is_writable(CACHEDIR) : (mkdir(CACHEDIR, 0755) && is_writable(CACHEDIR)) ? true : false
], // To cache view files for performance
'ext-simplexml' => [
'message' => Language::_('SystemRequirements.!warning.simplexml.recommended', true),