symfony2 : failed to write cache directory

后端 未结 10 1678
没有蜡笔的小新
没有蜡笔的小新 2020-12-12 11:21

I have had to use the

app/console cache:clear  command

to solve a problem when generating an entity.

I am now unable to load my ho

相关标签:
10条回答
  • 2020-12-12 11:52

    You probably aborted a clearcache halfway and now you already have an app/cache/dev_old.

    Try this (in the root of your project, assuming you're on a Unixy environment like OS X or Linux):

    rm -rf app/cache/dev*

    0 讨论(0)
  • 2020-12-12 11:53

    Maybe you forgot to change the permissions of app/cache app/log

    I'm using Ubuntu so

    sudo chmod -R 777 app/cache
    sudo chmod -R 777 app/logs
    sudo setfacl -dR -m u::rwX app/cache app/logs
    

    Hope it helps..

    0 讨论(0)
  • 2020-12-12 11:54

    If you face this error when you start Symfony project with docker (my Symfony version 5.1). Or errors like these:

    Uncaught Exception: Failed to write file "/var/www/html/mysite.com.local/var/cache/dev/App_KernelDevDebugContainer.xml"" while reading upstream

    Uncaught Warning: file_put_contents(/var/www/html/mysite.com.local/var/cache/dev/App_KernelDevDebugContainerDeprecations.log): failed to open stream: Permission denied" while reading upstream

    Fix below helped me.

    In Dockerfile for nginx container add line:

    RUN usermod -u 1000 www-data
    

    In Dockerfile for php-fpm container add line:

    RUN usermod -u 1000 www-data
    

    Then remove everything in directories "/var/cache", "/var/log" and rebuild docker's containers.

    0 讨论(0)
  • 2020-12-12 11:55

    if symfony version less than 2.8

    sudo chmod -R 777 app/cache/*

    if symfony version great than or equal 3.0

    sudo chmod -R 777 var/cache/*

    0 讨论(0)
  • 2020-12-12 11:59

    I move the whole directory from my Windows installation to a unix production server and I got the same error. To fix it, I just ran these two lines in unix and everything started to run fine

    rm -rf app/cache/*
    rm -rf app/logs/*
    
    0 讨论(0)
  • 2020-12-12 12:00

    i executed:

    ps aux | grep apache
    

    and got something like that:

    root     28147  0.0  5.4 326336 27024 ?        Ss   20:06   0:00 /usr/sbin/apache2 -k start
    www-data 28150  0.0  1.3 326368  6852 ?        S    20:06   0:00 /usr/sbin/apache2 -k start
    www-data 28151  0.0  4.4 329016 22124 ?        S    20:06   0:00 /usr/sbin/apache2 -k start
    www-data 28152  0.1  6.0 331252 30092 ?        S    20:06   0:00 /usr/sbin/apache2 -k start
    www-data 28153  0.0  1.3 326368  6852 ?        S    20:06   0:00 /usr/sbin/apache2 -k start
    www-data 28154  0.0  1.3 326368  6852 ?        S    20:06   0:00 /usr/sbin/apache2 -k start
    www-data 28157  0.0  1.3 326368  6852 ?        S    20:06   0:00 /usr/sbin/apache2 -k start
    user     28297  0.0  0.1  15736   924 pts/4    S+   20:12   0:00 grep --color=auto apache
    

    so my user with no access turned out to be www-data thus i executed commands:

    sudo chown -R www-data app/cache
    sudo chown -R www-data app/logs
    

    and it solved access errors.

    Never-ever use unsecure 777 for solving specific access probles:

    sudo chmod -R 777 app/cache
    sudo chmod -R 777 app/logs
    
    0 讨论(0)
提交回复
热议问题