RuntimeException: Unable to create the cache direc

2019-03-10 20:10发布

i installed the sonata admin bundle. After installation i refresh my page there is the cache problem then i use

rm -rf app/cache app/log

for remove the cache.then i also create the director using the command

mkdir app/cache app/log

then i got the new problem like this

Runtime Exception : Unable to create the cache directory (/var/www/sonata/app/cache/dev). Please help .

10条回答
戒情不戒烟
2楼-- · 2019-03-10 20:17

On a mac computer it will be:

$ sudo chown -R _www:_www var/cache
$ sudo chown -R _www:_www var/logs

If none of above work to you, call a "phpinfo()" on your php file and find for "User/Group" value. That's the user group to give permission to.

查看更多
Explosion°爆炸
3楼-- · 2019-03-10 20:22

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

and

$ chown -R www-data:www-data app/log

on the command line.

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.

查看更多
Summer. ? 凉城
4楼-- · 2019-03-10 20:23

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

查看更多
看我几分像从前
5楼-- · 2019-03-10 20:24

Changing the CHMOD might help but in case the cache annoys you during the deveopment you can just deactivate it. Navigate to your app config file (located in ../app/config/config.yml from your root directory). Scroll to the twig configuration settings (under twig:) and change the cache value (which should be pointing to the cache directory) to false like so:

twig:
    cache:  false

If you do not see any cache configuration entry, simply add the line above.

查看更多
我欲成王,谁敢阻挡
6楼-- · 2019-03-10 20:28

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
查看更多
何必那么认真
7楼-- · 2019-03-10 20:28

What is likely happening is that you are trying to create the file under apache/nginx. By default apache or nginx has umask set to 0022.

From: http://www.cyberciti.biz/tips/understanding-linux-unix-umask-value-usage.html

Explain Octal umask Mode 022 And 002

As I said earlier, if the default settings are not changed, files are created with the access mode 666 and directories with 777. In this example:

The default umask 002 used for normal user. With this mask default directory permissions are 775 and default file permissions are 664. The default umask for the root user is 022 result into default directory permissions are 755 and default file permissions are 644. For directories, the base permissions are (rwxrwxrwx) 0777 and for files they are 0666 (rw-rw-rw).

You will need to manually set the umask to 0002, and reset it back to its previous setting before you can create the directories.

查看更多
登录 后发表回答