131

I have a project on Laravel 5 and I work with it at the office and at home too. It works fine, but recently at home it stopped working. Laravel show me two ErrorException

file_put_contents(G:\project\storage\framework\views/751d8a0fd8a7d4138c09ceb6a34bb377aa2d6265.php):
failed to open stream: No such file or directory

and

file_put_contents(G:\project\storage\framework/sessions/aIXycR4LIAUBVIqZu0T590paOMIpV8vfZGIroEp0):
failed to open stream: No such file or directory

I'm searching problem decision with Google and find information about correct rights. All advice is about Linux, but I'am work in Windows at the office and at home too.

When I try to clear application cache and view cache, artisan talk to me - ...cleared. But cache data and views are present in storage.

How can I fix this problem?

Nimantha
  • 6,405
  • 6
  • 28
  • 69
Evgeniy
  • 3,219
  • 5
  • 25
  • 40
  • 7
    Yo can try cleaning the cache "php artisan cache:clear" I'm on linux, so I'm not sure about permission on windows, but check on folder properties if it's not read_only (right click on folder->properties) – educolo Oct 26 '17 at 17:30
  • @educolo I don't think the problem is about directory rights, because several month it was ok. – Evgeniy Oct 26 '17 at 17:57
  • Possible duplicate of [file\_put\_contents(meta/services.json): failed to open stream: Permission denied](https://stackoverflow.com/questions/23540083/file-put-contentsmeta-services-json-failed-to-open-stream-permission-denied) – kenorb Mar 22 '18 at 14:49
  • This solved my problem https://stackoverflow.com/a/72911821/7519779 – Nelson Katale Jul 08 '22 at 13:03

27 Answers27

215

The best way to solve this problem is, go to directory laravel/bootstrap/cache and delete config.php file. or you can rename it as well like config.php.old And your problem will be fixed.

danronmoon
  • 3,814
  • 5
  • 34
  • 56
Amit Verma
  • 2,427
  • 2
  • 7
  • 6
84

You should typically run the php artisan config:cache command as part of your production deployment routine. As a solution to your problem, I suggest you recreate the cache file, for faster configuration loading.

To do this, run the following Artisan commands on your command line

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

You can programmatically execute the command by adding the following to your routes:

Route::get('/clear-cache', function() {
    $exitCode = Artisan::call('cache:clear');
    $exitCode = Artisan::call('config:cache');
    return 'DONE'; //Return anything
});

And then call the clear-cache route from your browser.

Nimantha
  • 6,405
  • 6
  • 28
  • 69
Elisha Senoo
  • 3,489
  • 2
  • 22
  • 29
  • From at least Laravel 8 `config:clear` both clears and caches so there's no need to run two different commands. – Hashim Aziz Mar 12 '23 at 19:39
65

After some research I understand - I have very similar, but different root project locations and its cached in /bootstrap/cache. After cache clearing project started.

Nihal
  • 5,262
  • 7
  • 23
  • 41
Evgeniy
  • 3,219
  • 5
  • 25
  • 40
  • Wish I had seen this as it's the answer to my question about a missing service provider: https://stackoverflow.com/questions/58192052/laravel-spark-google2fa-provider-class-not-found-after-spark-update-to-v9-0 – j3py Oct 21 '19 at 22:48
24

Actually I faced this issue when I moved my project from server to local.

in

storage/framework

four basic folders are required cache, sessions, testing, views

In My case sessions was missing might be in gitignore.

So I manually created session folder and refreshed browser and it was working.

So any of the missing folder if we delete this problem can be solved.

shivanisdev
  • 687
  • 6
  • 16
14

I solved this problem via creating storage\framework\sessions folder.

tyasird
  • 926
  • 1
  • 12
  • 29
8

Apache + WSL on windows

This is a silly mistake, and a different answer compared to the others, but I'll add it because it happened to me.

If you use WSL (linux bash on windows) to manage your laravel application, while using your windows apache to run your server, then running any caching commands in the wsl will store the linux path rather than the windows path to the sessions and other folders.

Solution

Simply run the cache clearing commands in the powershell, rather than in WSL.

$ php artisan optimize

Was enough for me.

Azeirah
  • 6,176
  • 6
  • 25
  • 44
  • I ran into the same issue. I'm running Windows and also an instance of Linux on a VMWare virtual machine. This allows me to test both on Windows and Linux, but when I ran the `php artisan config:cache` command on Windows, my Linux would no longer load the application's web pages. Going into the bootstrap/cache folder and deleting the config.php file there resolved it. – David Tran Mar 24 '20 at 01:57
7

This type of issue generally occurs while migrating one server to another, one folder to another. Laravel keeps the cache and configuration (file name ) when the folder is different then this problem occurs.

Solution Run Following command:

php artisan config:cache

https://laravel.com/docs/5.6/configuration#configuration-caching

Bijaya Kumar Oli
  • 2,007
  • 19
  • 15
6

Try with these commands that have been useful with those errors

path\project\storage\framework\views...

php artisan view:clear

path\project\storage\framework/sessions...

php artisan config:cache
Carlos Avalos
  • 247
  • 4
  • 8
  • 2
    If you post a new answer while there are already multiple upvoted answers, you should add some more explanation to it such that others can learn from your answer – Nico Haase Jan 09 '19 at 09:20
4

In case of shared hosting when you do not have command line access simply navigate to laravel/bootstrap/cache folder and delete (or rename) config.php.

Nimantha
  • 6,405
  • 6
  • 28
  • 69
Dibyendu Mitra Roy
  • 1,604
  • 22
  • 20
4

I deleted the file /public_html/bootstrap/cache/config.php

Then I ran php artisan config:cache

Nimantha
  • 6,405
  • 6
  • 28
  • 69
Arafat
  • 358
  • 4
  • 11
3

This happens when you shift your website from local to live server or vice versa.
Simply go to bootstrap/cache and delete config.php.

Nimantha
  • 6,405
  • 6
  • 28
  • 69
Prem Sagar
  • 147
  • 2
  • 8
  • The top answer seems to suggest this already. Try to only add new information when posting answers to posts. – Timothy G. Jun 01 '21 at 20:31
3

The reason is related to cache or permission.

Firstly, go to directory laravel/bootstrap/cache and delete all files from cache.

  1. php artisan cache:clear
  2. php artisan config:clear
  3. php artisan config:cache

If the errors still happen. It may relates to permission Let's try command below (In my case user&group of laravel is nginx)

sudo chgrp -R nginx storage bootstrap/cache
sudo chmod -R ug+rwx storage bootstrap/cache
Nimantha
  • 6,405
  • 6
  • 28
  • 69
Richathon
  • 91
  • 2
  • 8
2

The reason for this problem is the cache files in localhost. According to that I've tried several things as follows to clear the cache on my project, but every time I've failed.

  • Tried to clear cahe commands by changing web.php file (with artisan codes)
  • Tried to clear cache by connecting SSH (via PUTTY)
  • Tried to host my project in Sub domain within create a new Public directory

So I've found a solution for this problem after each and every above steps failed and it worked for me perfectly. I deleted the cache.php file in host_route/bootstrap/cache directory.

Nimantha
  • 6,405
  • 6
  • 28
  • 69
2

If you are running laravel inside docker then access its filesystem

$ docker exec -it name-of-laravel-container /bin/bash

Next navigate to your laravel projects root directory. Make sure that you have inside storage/framework folder:

  1. cache
  2. sessions
  3. testing
  4. views

And they should be both readable and writable.

Bimal
  • 865
  • 10
  • 18
2

Changing name of /bootstrap/cache/config.php to config.php.old doesn't work for me neither clearing cache with the commands artisan

  1. php artisan config:clear
  2. php artisan cache:clear
  3. php artisan config:cache

And for some weird reason I can't change permission for the owner on the directories, so my solution was running my IDE (Visual Studio Code) as admin, and everything works.

My project is in an F:/ path of another disk.

Nimantha
  • 6,405
  • 6
  • 28
  • 69
hidroquino
  • 81
  • 1
  • 3
2

If nothing work try the following in the production environment

1-

composer install --optimize-autoloader --no-dev

2-

php artisan cache:clear

3-

php artisan config:clear

4-

php artisan view:clear

5-

php artisan config:cache

6-

php artisan route:cache

Works for me

Moh Alaraabi
  • 193
  • 6
1

Maybe there is an issue with your composer file. You could try:

  • composer install installs the vendor packages according to composer.lock (or creates composer.lock if not present),

  • composer update always regenerates composer.lock and installs the lastest versions of available packages based on composer.json

  • composer dump-autoload won’t download a thing. It just regenerates the list of all classes that need to be included in the project (autoload_classmap.php). Ideal for when you have a new class inside your project. Ideally, you execute composer dump-autoload -o , for a faster load of your webpages. The only reason it is not default, is because it takes a bit longer to generate (but is only slightly noticeable)

Above content originally quoted from Robin Brackez, What does ‘composer dump-autoload’ do in Laravel?

blackgreen
  • 34,072
  • 23
  • 111
  • 129
1

Clearing the contents of storage/framework/cache did the trick for me.

Nimantha
  • 6,405
  • 6
  • 28
  • 69
Peter Karsai
  • 99
  • 1
  • 4
0

In my case it was not anything that could be fixed with php artisan commands. The issue was folder permissions for the /storage folder. The error did not make that clear.

Peter Drinnan
  • 4,344
  • 1
  • 36
  • 29
0

The solution that worked for me is to just serve the app as admin if you are

  1. On mac or linux use sudo php artisan serve
  2. On Windows try to open CMD as an adminstrator and then go to project directory and run php artisan serve
Nimantha
  • 6,405
  • 6
  • 28
  • 69
0

I solved it clearing the content of:

/laravel/storage/framework/views

Then all the views were created again in that folder.

In my case these commands didn't fix it:

php artisan view:cache
php artisan route:cache
php artisan config:cache

I'm using Laravel 8 and in my case it seems that it was an issue with the permissions.

Luis Rodriguez
  • 355
  • 3
  • 7
0

For failing tests

I got this error when I made the mistake of deleting the tests/console folder along with the tests/source folder - specifically I was getting the following error from the Dusk tests running on my CI/CD environment (GitHub Actions):

ErrorException: file_put_contents(/home/runner/work/mysite/mysite/tests/Browser/console/Tests_Browser_MyDuskTest1_test_payments_are_working-0.log): Failed to open stream: No such file or directory

tests/source is an optional folder whereas apparently the tests/console is not and needs to exist in order for Dusk integrated tests to run.

I'm not sure why Dusk doesn't just create the folder dynamically when writing the console logs to disk, but either way, restoring the deleted console folder in the tests directory fixes the issue. If you can no longer restore the deleted folder, just creating the console folder with an empty .gitignore file in it should have the same effect.

Hashim Aziz
  • 4,074
  • 5
  • 38
  • 68
-1

I had similar problems because of .gitignore for the /storage folder on first machine, then cloned repository on second machine and laravel was revision to write down sessions cache

So, manually creating folder /storage/sessions might be an solution..

Sergey Khmelevskoy
  • 2,429
  • 3
  • 19
  • 43
-1

I used Laravel 8, This is my solution:

Goto:
storage/framework/cache/data
set permission directory data is 777

Nimantha
  • 6,405
  • 6
  • 28
  • 69
Infomaster
  • 793
  • 7
  • 8
-1

This did the magic for me. chmod -Rf 0777 storage

Unique
  • 9
  • 3
-1

In my case, I set APP_DEBUG=false since it is a production server, I decided to set it back to true and then it showed Missing BC Math or GMP extension

That is how I solved my own issue, setting APP_DEBUG=true might not work for everybody.

aphoe
  • 2,586
  • 1
  • 27
  • 31
-1

I went all the way, but I did not get the answer.
I just rename cache folder in storage/framework/ to cache1 and solved my problem.

Nimantha
  • 6,405
  • 6
  • 28
  • 69
asghar
  • 437
  • 5
  • 5
  • This is the same as clearing the cache, which has already been mentioned https://stackoverflow.com/a/64413142/2227743 – Eric Aya Sep 05 '21 at 09:00
  • yes but clear cache not work for me. after rename cache folder fixed error. – asghar Sep 06 '21 at 07:40