How do I fix the errors “Unable to write in the cache directory” or “The directory matomo/tmp/cache/*” is not writable.”?
It may happen that the User Interface of Matomo fails to load and display an error message which can mention Unable to write in the cache directory
or The directory tmp/cache/* is not writable
. This indicates there is a small issue around folders and/or file permissions within the Matomo directory. The full error message could be A fatal error occurred. The following error just broke Matomo (v3.10.0): An exception has been thrown during the rendering of a template "Unable to write in the cache directory"
These issues can be addressed by setting the correct permissions that will let processes read and write the tmp/
folder.
General solution: if your web server username is www-data
then you can have your webserver own the files in this directory (replace www-data
by the web server username, sometimes called apache
):
sudo chown -R www-data:www-data /var/www/html/matomo/tmp/*
If your server is running SELinux or CentOS, you may be able to fix the issue with the following commands:
chcon -t httpd_sys_content_rw_t /var/www/matomo/tmp
chcon -R -t httpd_sys_content_rw_t /var/www/matomo/tmp/tracker/
chcon -R -t httpd_sys_content_rw_t /var/www/matomo/tmp/cache
systemctl reload httpd.service
If this error keeps occurring, the issue may be that the scheduled task (crontab) for the core:archive console command is running and writing these files as a different user. To solve the issue you want to modify your crontab so that it runs the core:archive
command as the web server user, for example running as www-data
or apache
. See the the user guide for more details.
It has also sometimes helped to upgrade PHP to use a recent PHP release.
If you still experience this issue after following the steps above, please get in touch with us at matomo.org/contact and we will help troubleshoot further.