Decoding the _cake_core_ Cache Write Failure
When a CakePHP application throws a CacheException stating that the _cake_core_ engine is not properly configured, it usually points to a single root cause: insufficient directory permissions on the cache storage path. The error message explicitly states that /var/www/bloglic-2013/cake/app/tmp/cache/persistent/ is not writable. Despite this clear indication, developers often struggle because the file system permissions on the PHP files themselves appear correct, leading to confusion about where to apply chmod.
The distinction between file permissions and directory write permissions is critical here. In the provided source material, the user lists permissions for the CakePHP library core files (like Cache.php) as -rwxr-xr-x or similar, which allows the web server user to read and execute them. However, the error originates from the FileEngine, which attempts to write serialized data into a specific directory. The logs show the web server process is likely running under a user like www-data, apache, or nginx, while the directory owner is listed as marc.
If the cache directory is owned by marc but the web server runs as www-data, the server cannot create new cache files even if it can read existing ones. This is a classic Unix permission mismatch. The fix requires changing the ownership of the entire cache tree to match the web server user or granting write permissions to the group that owns the directory.
Identifying the Cache Paths
CakePHP 2.x, which appears to be the version in use based on the file paths, defaults to using app/tmp/cache for its internal caching needs. The error log specifically mentions /var/www/bloglic-2013/cake/app/tmp/cache/persistent/. This is a subdirectory within the default cache structure.
You need to identify exactly which directory the application is trying to write to. By default, CakePHP creates separate directories for different cache profiles (like persistent, model, view). If you are using the default configuration, the application will attempt to create these subdirectories dynamically. If the parent directory (app/tmp/cache) does not have write permissions, the creation of these subdirectories fails immediately, triggering the exception before any specific profile logic is reached.
Resolving Ownership with chown and chmod
The most robust solution is to align the ownership of the cache directories with the web server user. Since the source material shows the owner is marc, and assuming the web server runs as www-data (a common default on Linux distributions), you should execute a command to transfer ownership recursively.
Run the following command in your shell, replacing www-data with the actual user running your PHP process (check via ps aux | grep php-fpm or your web server configuration):
sudo chown -R www-data:www-data /var/www/bloglic-2013/cake/app/tmp/cache/
This command ensures that any new files created by the cache engine will be owned by the web server user, preventing permission denied errors. If you prefer not to change ownership globally, you can grant write permissions to the group or make the directory world-writable, though the latter is less secure:
sudo chmod -R 770 /var/www/bloglic-2013/cake/app/tmp/cache/
However, changing ownership is generally preferred for multi-user environments.
Verifying Configuration and SELinux
Sometimes, even with correct Unix permissions, the cache engine remains non-functional due to security modules like SELinux or AppArmor. If you are on a RHEL-based system, SELinux might block writes to /tmp or specific application directories even if chmod succeeded. Check the current SELinux status:
getenforce
If it returns Enforcing, and you have corrected the permissions but still see the exception, you may need to add a local context rule or switch to Permissive temporarily for debugging. Additionally, ensure that the tmp directory is not mounted with noexec or nosuid options in /etc/fstab.
Alternative: Switching Cache Engines
If modifying file system permissions poses a security risk or if you are on a shared hosting environment where you lack sudo access to change ownership of the entire tree, consider switching to an external cache engine like Redis or Memcached. These engines do not rely on local file system write permissions for the core cache directory in the same way. You would update your Config/bootstrap.php or app/Config/core.php to define a new cache configuration:
Cache::config('default', [
'engine' => 'Redis',
'prefix' => ''
]);
This approach bypasses the FileEngine entirely, effectively resolving the _cake_core_ write failure without touching file permissions. However, this introduces a dependency on an external service and requires proper network connectivity and Redis configuration, which is a significant trade-off compared to fixing local permissions.
In summary, the error is almost always a permission mismatch between the web server user and the cache directory owner. Fixing the ownership of /var/www/bloglic-2013/cake/app/tmp/cache/ to the web server user is the standard and most effective resolution.