php - Laravel Storage Cache folders owned by root causes fail in clearing cache
Get the solution ↓↓↓I have a laravel 7 application running on a server (Ubuntu 18.04 LTS, apache2 webserver). My problem is, thatphp artisan cache:clear
does return "Failed to clear cache. Make sure you have the appropriate permissions."
I tried the following approaches without success:
chmod -R 775 storage
php artisan config:cache
- manually deleting "bootstrap/cache/services.php" + "bootstrap/cache/packages.php" + "bootstrap/cache/config.php"
New created cache folders in "storage/framework/cache/data" are sometimes owned by user root, this seems to be the problem.
If I delete these folders manually it works till new root folders are created.
Withps -aux
I saw that the laravel process was running from user root. I changed this withsudo -u myusername
, but this didnt change the behaviour. I am starting the laravel application (php artisan serve
) within the rc.local script on server restart.
The current user "myusername" is in the group www-data.
Answer
Solution:
You have to run webserver from the user that is belongs to the same usergroup with your current user. By defaultrc.local
call commands fromroot
user, which is not what you need.
Edit yourrc.local
this way:
su user01 -c 'php /var/www/artisan serve'
Whereuser01
is your current user and/var/www/artisan
is full path to your artisan file. Also maybe you should specify full path to your php bin file, like/usr/bin/php
or else.
More details here
Answer
Solution:
The problem should be that you don't have folders in storage path. You should have
- storage/framework/sessions
- storage/framework/views
- storage/framework/cache
Try to create empty folders, it should be work.
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: trying to access array offset on value of type null
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.