Framework: file_put_contents(.../storage/framework/cache/data/): failed to open stream: No such file or directory

Created on 12 Aug 2018  路  14Comments  路  Source: laravel/framework

  • Laravel Version: 5.6
  • PHP Version: 7.1
  • Database Driver & Version: MySQL 5.7.23

Description:

I got an error

file_put_contents(.../storage/framework/cache/data///): failed to open stream: No such file or directory

<some_cache_index> is always the same.
I have CACHE_DRIVER=file inside .env.
Error occurs on certain cross-domain request which fetches some data from database.

What I tried so far: php artisan cache:clear, didn't helped. storage/framework/cache/data/ is empty, but why framework ask that file each time? How can I make framework to forgot that file?

Most helpful comment

php artisan config:cache solved my issue.

All 14 comments

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.

@X-Coder264 Thank you! I've also tried
sudo chown -R $USER:www-data storage/*, sudo chown -R $USER storage/* - no success.

I guess, chmod -R 775 storage solved my problem.

I had a similar issue on Windows Server 2012, SQL Server 2012, Laravel 5.5, PHP 7.2.10 and IIS 6.2 (Build 9200) and I solved it by doing the following:

  • Stop IIS
  • Moving all contents of my Laravel application folder to a new folder, except for the storage folder.
  • Copy all content inside the storage directory, except for the frameworks directory.
  • Manually created the cache, sessions, testing and views directory, which are the four default directories inside of the framework directory.

I have decided to do that because I was deleting the storage/framework/cache directory and the files were back as if I had never deleted them in the first place. Also, the main reason for doing all of this was because if my users were logging in with a wrong password, they would get the error mentioned in the title of this thread.

I hope this helps someone someday.

php artisan config:cache solved my issue.

in my case it worked to delete the bootstrap/cache/config.php file.

php artisan config:cache solved my issue.

It's work for me. Thank's

@mxl @hosamalzagh @jackgoh @yazansalhi @YNathaly @nadhifhayazee @Pezadilla still waiting for your feedback

in my case it worked to delete the bootstrap/cache/config.php file.

Perfect solution

In my case i do php artisan config:cache but now my app is totally down with this error Fatal error: Uncaught Error: Call to a member function connection() on null in /var/www/html/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:1201 Stack trace: #0 /var/www/html/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php(1167): Illuminate\Database\Eloquent\Model::resolveConnection(NULL) #1 /var/www/html/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php(997): Illuminate\Database\Eloquent\Model->getConnection() #2 /var/www/html/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php(912): Illuminate\Database\Eloquent\Model->newBaseQueryBuilder() #3 /var/www/html/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php(950): Illuminate\Database\Eloquent\Model->newModelQuery() #4 /var/www/html/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php(901): Illuminate\Database\Eloquent\Model->newQueryWithoutScopes() #5 /var/www/html/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php(1570): Illuminate\Database\Eloquent in /var/www/html/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php on line 1201

can anyone help me?

In my case the problem was that he data folder inside storage/framework belonged to root instead of the correct user. chown -R <user: group> data did the trick.

Replace <user: group> with your own user and group. "<>" symbols are not supposed to be there.

go to /bootstrap/app.php
edit your app.php file and see that the storage directory is not hardcoded to the path /storage/framework/cache/data/

mine looked something like this: $app->useStoragePath('../../../logs/Reports' );

I tried everything written above, but I still get this error.

ErrorException : file_put_contents(/var/www/storage/framework/cache/data/5e/3c/5e3cbbed47195384f39edf30b47d8cd8245cdff8): failed to open stream: No such file or directory

I am using Laradock in project. it is working normally but in phpunit is not working.

Hey everyone,

I'm locking this issue because it either has gone off-topic, become a dumping ground for things which shouldn't be in an issue tracker or is just too old. Please try to discuss things further on one of the below channels:

Was this page helpful?
0 / 5 - 0 ratings