CodeIgniter 4 cannot write its cache files
CodeIgniter\Cache\Exceptions\CacheException: Cache unable to write to /var/www/app/writable/cache/Short answer
CodeIgniter 4's file cache needs a cache directory that the web server can really write to. On a new project the writable folder is usually owned by another user, or the Paths config points at a writable folder that no longer matches the project layout.
Fix it fast
1Find out which cause you have
See who owns the writable folder and which user runs PHP.
ls -ld writable writable/cache ps -o user= -C php-fpm8.3 | sort -u2Match what you see, then jump to its fix
What does the error look like?
CodeIgniter\Cache\Exceptions\CacheException: Cache unable to write to /var/www/app/writable/cache/
Cause 1 of 2
The writable folder is not writable by the web server user
1Check
The file cache needs a directory that the application can really write to. The install guide says to set permissions on the writable folder so it is writable by the account your web server uses.
ls -ld writable writable/cache2Fix
Give the web server user (www-data on Ubuntu) write access to writable.
sudo chown -R www-data:www-data writable
sudo chmod -R u+rwX,g+rwX writable3Verify
Reload the page; the exception is gone and files appear in writable/cache.
ls writable/cacheConfirmed by codeigniter.com
Cause 2 of 2
The project was moved and Paths.php still points to the old folders
1Check
The writable folder holds cache, logs and uploads. If you relocated main directories, the settings live in app/Config/Paths.php and must match.
grep -n -E "directory" app/Config/Paths.php2Fix
Correct the writable path in Paths.php so it points to the folder that exists, then fix its permissions as above.
// app/Config/Paths.php
public string $writableDirectory = __DIR__ . '/../../writable';3Verify
The path in the error message now exists and the cache writes.
php spark cache:clearConfirmed by codeigniter.com
How do I stop it coming back?
- Point the web server document root at public, and keep writable outside it where possible.
- Run deploy commands as the same user the web server uses, or re-apply ownership after deploy.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Back end
Apache returns 503 or 504 because PHP-FPM did not answer in time
Error dispatching request
Apache sent the request to PHP-FPM and gave up waiting.
3 causes, each with a fixBack end
AWS SDK for PHP cannot get credentials from the instance profile metadata server
Error retrieving credentials from the instance profile metadata server.
The SDK tries the EC2 instance metadata service when it has no valid credentials from anywhere earlier in its chain.
4 causes, each with a fixBack end
AWS SDK for PHP rejects requests: the signature is from the future
Signature not yet current: {date} is still later than {date}
AWS compares the timestamp in your signed request with its own clock.
2 causes, each with a fixBack end
CodeIgniter 3 loads the model but the property is undefined
The model name you are loading is the name of a resource that is already being used: user
CodeIgniter 3 expects a model file named like its class, with the first letter capitalised, for example User_model.php holding class User_model.
2 causes, each with a fixBack end
CodeIgniter 3 stops with "Your system folder path does not appear to be set correctly"
503 Service Unavailable
CodeIgniter 3's front controller resolves $system_path and then checks that the result is a directory.
3 causes, each with a fixBack end
Composer cannot reach repo.packagist.org on port 443
Operation timed out after 300000 milliseconds
When Composer cannot reach repo.packagist.org, run composer diagnose first; it tests the connection and the certificate store.
4 causes, each with a fix