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

LaravelComposer Php

Laravel Problem Overview


Laravel was displaying to me "Access denied for user 'homestead'@'localhost' (using password: YES)". One solution for this was clearing the cache and the config cache stored, all this with these three commands:

php artisan cache:clear
php artisan config:clear
php artisan config:cache

After php artisan cache:clear, terminal says:

Failed to clear cache. Make sure you have the appropriate permissions. (with red background)

Doing the second and third code (php artisan config:clear and php artisan config:cache) works fine! But it still gives me the error when typing the first line. Can anyone explain why?

Laravel Solutions


Solution 1 - Laravel

If the data directory doesn't exist under (storage/framework/cache/data), then you will have this error.

This data directory doesn't exist by default on a fresh/new installation.

Creating the data directory manually at (storage/framework/cache) should fix this issue.

Solution 2 - Laravel

Try deleting these cached files under bootstrap folder:

/bootstrap/cache/packages.php
/bootstrap/cache/services.php
/bootstrap/cache/config.php

Then run php artisan cache:clear

Solution 3 - Laravel

Calling

php artisan config:cache 

before

php artisan cache:clear

fixed the issue.

Solution 4 - Laravel

Just only add folder named data in storage/framework/cache/ and try:

php artisan cache:clear

Solution 5 - Laravel

enter image description here

First try:

Check if there is a "data" folder inside "storage/framework/cache/". If there is not, then create it manually. (create a new folder with name "data")

Option 2:

If there is a "data" folder inside "storage/framework/cache/". Remove ALL existing folders inside there.

Then final, running this:

php artisan cache:clear

This should fix this issue: "Failed to clear cache. Make sure you have the appropriate permissions."

Solution 6 - Laravel

Calling the following 4 commands should fix most of the permission issues on laravel.

sudo chown -R $USER:www-data storage
sudo chown -R $USER:www-data bootstrap/cache
chmod -R 775 storage
chmod -R 775 bootstrap/cache

Basically, chown -R $USER:www-data what this does is it set current user $USER as owner and www-data as group and chmod -R 775 gives 7 to user,7 to group and 5 to other.

#PS: You need to run above command from the laravel project directory, else, you need to provide full path like /var/www/project_name/storage

Solution 7 - Laravel

In Laravel 8 I solved my issue by first running composer dump-autoload and then used php artisan config:cache

Solution 8 - Laravel

Deleting and adding back the ./storage/framework/cache/data folder worked for me.

Solution 9 - Laravel

You should update the permission using the below steps:

  1. Check user using command "whoami" then let output is "ironman"
  2. Run below command if "data" folder exists in the cache directory

sudo chown -R ironman:ironman storage/framework/cache/data/

This will resolve your below issueenter image description here

Solution 10 - Laravel

I ran my project in a docker container, then later tried accessing it via laragon, I had similar issue, this was due to compiled configurations in /bootstrap/cache/config.php.

I fixed fit by running php artisan config:clear, this deletes the /bootstrap/cache/config.php file automatically.

Solution 11 - Laravel

I had the same problem but noticed if you run php artisan config:clear it also by default runs cache:clear right after it so when you run it again there is not cache in it and gives that error. you only need to run php artisan config:clear. I am not sure why cache:clear fails when its ran alone but running the config:clear is a good alternative.

Here is a helpful alias i use to clear everything in the app.

laraclear='php artisan config:cache && php artisan config:clear && php artisan view:clear && php artisan route:clear && php artisan telescope:clear && php artisan debugbar:clear'

Remove any unwanted commands that you do not use in it.

Solution 12 - Laravel

(For MAC Users)

Sometimes, it means current user don't have sufficient permission to the storage/framework/cache/data/ folder. Run

  1. sudo chmod -R ug+rwx storage/framework/cache/data/

then

  1. php artisan cache:clear

Hope sometimes it work for you.

Solution 13 - Laravel

You may need to clear the autoloader with composer dump-autoload

If that doesn't work you can manually remove the following non-tracked (usually) files to clear the autoloader and cache if they get jammed up:

/bootstrap/cache/packages.php

/bootstrap/cache/services.php

Solution 14 - Laravel

In my case the problem was I had 'CACHE_DRIVER=memcached' in .env but didn't have memcached installed. Switching to the file driver or installing memcached fixed the problem for me.

Solution 15 - Laravel

Delete all subfolders under:

storage/framework/cache/data/

Solution 16 - Laravel

Can't this solve it?

$php artisan optimize:clear
Compiled views cleared!
Application cache cleared!
Route cache cleared!
Configuration cache cleared!
Compiled services and packages files removed!

Solution 17 - Laravel

Had the same problem on my vagrant/homestead VM. All the other things in this thread didn't help.

The solution was vagrant reload --provision

Solution 18 - Laravel

Giving 775 permission to the storage directory solved this problem for me.

sudo chmod -R 775 storage

Solution 19 - Laravel

I am running my project in Homestead.

My environment : >Ubuntu1~20.04+ Laravel 6.20.26

My output

enter image description here

display real fatal info

Edit src/Illuminate/Filesystem/Filesystem.php 598:14 original code:

if (! $preserve) {
    @rmdir($directory);
}

debug code

if (! $preserve) {
    rmdir($directory);
}

Then re-execute php artisan cache:clear The output changed:

enter image description here

Then, I just resolve Text file busy

Solution 20 - Laravel

For Laravel Homestead on Windows:

In your .env file, change your CACHE_DRIVER from file to memcached.

Run php artisan cache:clear.

Solution 21 - Laravel

got the same error. try giving chmod 777 permission in the concerned folder

Solution 22 - Laravel

My guess is you have a permission/ownership problem. Either set up the permissions correctly or recursively delete the cache folder manually and re-create it:

sudo rm -Rf storage/framework/cache
mkdir storage/framework/cache

Solution 23 - Laravel

maybe you need to chmod 777 -R storage folder. and i think it can also chown www-data:www-data

Solution 24 - Laravel

Incase non of these works for you, simply run your php artisan cache:clear command with sudo. e.g. sudo php artisan cache:clear Thank me later~!

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionE.AkioView Question on Stackoverflow
Solution 1 - LaravelMytho XYView Answer on Stackoverflow
Solution 2 - LaravelSidView Answer on Stackoverflow
Solution 3 - LaravelMartin CupView Answer on Stackoverflow
Solution 4 - LaravelKamleshView Answer on Stackoverflow
Solution 5 - LaravelRaymondView Answer on Stackoverflow
Solution 6 - LaravelSaroj ShresthaView Answer on Stackoverflow
Solution 7 - LaravelAbid_015View Answer on Stackoverflow
Solution 8 - LaravelThomas JonesView Answer on Stackoverflow
Solution 9 - LaravelRanjan FadiaView Answer on Stackoverflow
Solution 10 - LaravelAbdulmatin SanniView Answer on Stackoverflow
Solution 11 - LaravelLaravel CoderView Answer on Stackoverflow
Solution 12 - LaravelJunayedView Answer on Stackoverflow
Solution 13 - LaraveljeremykenedyView Answer on Stackoverflow
Solution 14 - LaravelStep29View Answer on Stackoverflow
Solution 15 - LaravelSkywalkerView Answer on Stackoverflow
Solution 16 - Laraveldaiki.nView Answer on Stackoverflow
Solution 17 - LaravelPixelprotagonistView Answer on Stackoverflow
Solution 18 - LaravelhabibView Answer on Stackoverflow
Solution 19 - LaravelzzrView Answer on Stackoverflow
Solution 20 - LaravelScott BrownView Answer on Stackoverflow
Solution 21 - LaravelTanzeela YousufView Answer on Stackoverflow
Solution 22 - LaravelRishi RanjanView Answer on Stackoverflow
Solution 23 - LaravelMartin AdiputraView Answer on Stackoverflow
Solution 24 - LaravelDevmaleeqView Answer on Stackoverflow