RuntimeException: Unable to create the cache directory (/var/www/sonata/app/cache/dev) RuntimeException: Unable to create the cache directory (/var/www/sonata/app/cache/dev) php php

RuntimeException: Unable to create the cache directory (/var/www/sonata/app/cache/dev)


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/cachechown -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.


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


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/logssudo chown -R www-data:www-data var/cachesudo rm -rf var/logs/* var/cache/*