RuntimeException: Unable to create the cache directory (/var/www/sonata/app/cache/dev)
Solution 1
It looks like a file/directory permission problem. The directory has to be writeable by the webserver. After creating the directory you should adjust the permissions with
chown -R www-data:www-data app/cache
chown -R www-data:www-data app/log
Or for Symfony 4+:
chown -R www-data:www-data var
This only works on linux systems. The user and group depends on your distribution. On Debian and Ubuntu this should be www-data
, on CentOS it's afaik apache
.
Another solution would be not to delete the whole folders but only their contents via
$ rm -rf app/log/* app/cache/*
But please be careful with this command.
Solution 2
This solution is correct : https://stackoverflow.com/a/20128013/2400373
But is necessary change the 2 commands in Symfony3
:
First you should is inside the folder of project:
$ sudo chown -R www-data:www-data var/cache
$ sudo chown -R www-data:www-data var/logs
After delete the cache:
$ sudo rm -rf var/cache/*
$ sudo rm -rf var/logs/*
Regards
Solution 3
I solved it changing user and group of folder var/cache
and var/logs
, then I cleaned cache:
sudo chown -R www-data:www-data var/logs
sudo chown -R www-data:www-data var/cache
sudo rm -rf var/logs/* var/cache/*
Solution 4
And for centos:
chown -R apache:apache app/cache
if you're coming here for Symfony Help you might have to do this as well if you delete the entire app/logs folder
chown -R apache:apache app/logs
Solution 5
I found a similar problem when I was using the PHP symfony as the error picture. I found it after running command
php bin/console cache:clear
I solved it by removed everything inside the folder /app/var/cache
Comments
-
user2779489 about 3 years
I installed the Sonata admin bundle.
After installation i refresh my page there is the cache problem then i use the following command to remove the cache:rm -rf app/cache app/log
Then I recreate the directory:
mkdir app/cache app/log
But I got the following error:
Runtime Exception : Unable to create the cache directory (/var/www/sonata/app/cache/dev).