E.Akio
E.Akio

Reputation: 2398

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

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?

Upvotes: 167

Views: 259643

Answers (30)

Ali Muhammad
Ali Muhammad

Reputation: 31

my problem i was runing cron job with root user Remove the root Cron Job

First, remove the cron job that runs as root:

sudo crontab -e

and remove all the data

* * * * * cd /var/www/html/foldr && /bin/php artisan schedule:run >> /dev/null 2>&1

then run

crontab -e 

add these lines

* * * * * cd /var/www/html/foldr && /bin/php artisan schedule:run >> /dev/null 2>&1

Verify the Cron Job

Ensure the cron job is set up correctly for user

crontab -l

Upvotes: 0

GigaTera
GigaTera

Reputation: 1280

enter image description here

make sure you have this folder path, if not... just create it.

it will solve ur problem

Upvotes: 3

Bulbul Sarker
Bulbul Sarker

Reputation: 102

Ubuntu 20.04 
My Problem is.
UnexpectedValueException 

There is no existing directory at "/home/mehedihasansagor/work-place/all-code/nik/storage/logs" and it could not be created: Permission denied

When I removed these files, Then the problem is solved

config.php
packages.php
routes-v7.php
services.php

php artisan optimize:clear

Upvotes: 1

MiraTech
MiraTech

Reputation: 1352

You just need to UPDATE the cache folder owner:

First check the current user with: whoami // output: miratech

Second run sudo chown -R mirad:mirad storage/framework/cache/

Finally re-run php artisan cache:clear

This error: enter image description here

Will be FIXED and you should see something similar to:

enter image description here

Upvotes: 0

Rithy
Rithy

Reputation: 184

For my case, I have all the directory, but we have 2 users.

  1. deployer
  2. www-data

The cache path are created with www-data, but the deployer has no write access . So we need to give the access to the deployer user.

setfacl -R -m u:deployer:rwx /var/www/html

Upvotes: 0

Manjesh Yadav
Manjesh Yadav

Reputation: 45

  1. In my case, there is no cache available that's why the artisan is unable to delete or reset the cache.

  2. First browse the website and allow it to create some cache then try to clear it.

  3. You can check whether the cache is available or not in directory storage/framework/cache/*

Upvotes: 0

Mohammed AL MahmoOd
Mohammed AL MahmoOd

Reputation: 101

Solution : update the permission :

  1. get user name by this command : whoami

  2. Run command if "data" folderexists in the cache directory.

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

Upvotes: 1

Bravo Gidi
Bravo Gidi

Reputation: 31

Ensure APP_URL is properly set on .env file. Changing http to https in the APP_URL variable on .env file solved it for me.

Upvotes: 0

user527892
user527892

Reputation:

For Laravel Homestead on Windows:

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

Run php artisan cache:clear.

Upvotes: 1

Skywalker
Skywalker

Reputation: 1774

Delete all subfolders under:

storage/framework/cache/data/

Upvotes: 5

Step29
Step29

Reputation: 61

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.

Upvotes: 4

zzr
zzr

Reputation: 11

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

Upvotes: 0

Junayed
Junayed

Reputation: 121

(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.

Upvotes: 5

Saroj Shrestha
Saroj Shrestha

Reputation: 2895

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

Upvotes: 48

Ranjan Fadia
Ranjan Fadia

Reputation: 1733

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

Upvotes: 9

Abid_niazi_15
Abid_niazi_15

Reputation: 875

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

Upvotes: 23

Rishi Ranjan
Rishi Ranjan

Reputation: 195

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

Upvotes: -2

habib
habib

Reputation: 1594

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

sudo chmod -R 775 storage

Upvotes: 2

Thomas Jones
Thomas Jones

Reputation: 106

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

Upvotes: 9

Sid
Sid

Reputation: 4510

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

Upvotes: 145

Devmaleeq
Devmaleeq

Reputation: 586

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~!

Upvotes: -4

Pixelprotagonist
Pixelprotagonist

Reputation: 11

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

Upvotes: 0

Raymond
Raymond

Reputation: 1429

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."

Upvotes: 44

n00
n00

Reputation: 41

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!

Upvotes: 2

Laravel Coder
Laravel Coder

Reputation: 21

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.

Upvotes: 2

Martin Cup
Martin Cup

Reputation: 2582

Calling

php artisan config:cache 

before

php artisan cache:clear

fixed the issue.

Upvotes: 66

Abdulmatin Sanni
Abdulmatin Sanni

Reputation: 39

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.

Upvotes: 2

Mytho XY
Mytho XY

Reputation: 4712

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.

Upvotes: 468

Kamlesh
Kamlesh

Reputation: 6135

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

php artisan cache:clear

Upvotes: 50

jeremykenedy
jeremykenedy

Reputation: 4285

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

Upvotes: 2

Related Questions