Thierry Maasdam
Thierry Maasdam

Reputation: 1054

Laravel: file_put_contents() permission denied — correct storage/framework/cache permissions?

I'm having struggles with editing the Laravel cache, which is located in storage/framework/cache. I've got a job running that saves to a certain cache, but every time the job runs, this error occurs:

ERROR: file_put_contents(/var/www/html/---/storage/framework/cache/data/3c/c7/3cc7fd54b5a3cb08ceb0754f58371cec1196159a): failed to open stream: Permission denied

Details

Any help is appreciated! Thank you in advance.

Upvotes: 16

Views: 44213

Answers (5)

Jaydip Pandey
Jaydip Pandey

Reputation: 1

To resolve the issue, I executed the command sudo php artisan optimize:clear to completely clear the optimization. This action prevented the problem from reoccurring.

Upvotes: -2

lewis4u
lewis4u

Reputation: 15057

If you're using redis then you should set the .env variable

CACHE_DRIVER=redis

Upvotes: -1

Tony Nguyen
Tony Nguyen

Reputation: 31

Actually just need

php artisan cache:clear 

But its just temporary, when login account with new ip or something. Its still got issued.

So try to chmod:

chmod -R 775 storage

and

chmod -R 775 storage/*

Its solve problems

Upvotes: 3

Ismoil  Shifoev
Ismoil Shifoev

Reputation: 6011

1) If you take a look at your cache.php config file you'll see that for the file driver the storage/framework/cache/data folder is set for writing:

'file' => [
    'driver' => 'file',
    'path' => storage_path('framework/cache/data'),
],

That means that the permissions for that folder must be properly set so that the web server user can successfully write to that folder.

2) or you can just running this command for me it solved my problem

php artisan cache:clear 
chmod -R 775 storage/
composer dump-autoload

Upvotes: 3

Thierry Maasdam
Thierry Maasdam

Reputation: 1054

I cleared the cache completely using sudo php artisan cache:clear. Afterwards, the problem never occurred.

Opposed to Ismoil's answer: never make the Laravel storage folder 777. It poses a security risk.

Upvotes: 31

Related Questions