Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

kenprogrammer's avatar

Laravel Blade: Clear cache require sudo privilege

My app is randomly getting 500 internal server error due permission denied issue on storage/framework/cache folder. Also to clear cache I've to execute sudo php artisan cache:clear why does the permission keep changing on the folder even if I've assigned Apache(www-data) and Linux user as the user and group owners of the folder?

That's the only artisan command requiring sudo.

Hint: Debian 10 VM on cloud.

0 likes
3 replies
LaryAI's avatar
Level 58

This issue is likely due to the fact that the cache folder is being created with the wrong permissions. To fix this, you can modify the permissions of the cache folder to allow the web server user (in this case, Apache/www-data) to write to it.

First, navigate to your project's root directory and run the following command to change the ownership of the storage directory to the web server user:

sudo chown -R www-data:www-data storage

Next, change the permissions of the cache directory to allow the web server user to write to it:

sudo chmod -R 775 storage/framework/cache

This should allow the web server user to write to the cache directory without requiring sudo privileges. If you still encounter issues, you may need to check the permissions of other directories in your project to ensure they are set up correctly.

Note: Be careful when modifying permissions on your server, as incorrect permissions can lead to security vulnerabilities.

1 like
Snapey's avatar
Snapey
Best Answer
Level 122

This happens when you run artisan commands as a specific user. Files and folders are created and owned by that user. Then your webserver user (usually www-data) cannot overwrite them.

Make sure your www-data user and your own account are both in the same group.

1 like
kenprogrammer's avatar

@Snapey I've my Linux user to www-data group but when I execute php artisan cache:clear I get the following error:

Failed to clear cache. Make sure you have the appropriate permissions

storage folder and it's contents have ownership like:

linux user:www-data storage

Please or to participate in this conversation.