Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

CodeIgniter 4 cannot write its cache files

ErrorCodeIgniter\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.

  • Applies to CodeIgniter 4.5, PHP 8.3, Ubuntu 24.04
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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 -u
  2. 2Match what you see, then jump to its fix

    1. 1ls shows the folder owned by root or your own user, mode 755The writable folder is not writable by the web server userFix
    2. 2The path in the error does not exist, or points outside the projectThe project was moved and Paths.php still points to the old foldersFix

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/cache

2Fix

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 writable

3Verify

Reload the page; the exception is gone and files appear in writable/cache.

ls writable/cache

Confirmed by codeigniter.com

Did this fix it?

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.php

2Fix

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:clear

Confirmed by codeigniter.com

Did this fix it?

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

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 fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.