Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel Storage Cache folders owned by root causes fail in clearing cache

I have a laravel 7 application running on a server (Ubuntu 18.04 LTS, apache2 webserver). My problem is, that php 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.

With ps -aux I saw that the laravel process was running from user root. I changed this with sudo -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.

like image 353
Gommiboum Avatar asked Nov 16 '22 07:11

Gommiboum


1 Answers

You have to run webserver from the user that is belongs to the same usergroup with your current user. By default rc.local call commands from root user, which is not what you need.

Edit your rc.local this way:

su user01 -c 'php /var/www/artisan serve'

Where user01 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

like image 186
krylov123 Avatar answered Dec 09 '22 19:12

krylov123