[php] Laravel 5 show ErrorException file_put_contents failed to open stream: No such file or directory

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?

Thanks in advance!

This question is related to php windows laravel laravel-5

The answer is


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 fix. Happy coding :-)


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.

I hope this is helpful.


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.


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.


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


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 and you are all done!


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

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.


The best way to solve this problem is, go to directory laravel/bootstrap/cache and delete all files from cache.

To do this, run the following Artisan commands on your command line
1. php artisan config:clear
2. php artisan cache:clear
3. php artisan config:cache

In your panel or server, you can execute commands by adding the following to your routes:

    Route::get('/clear-cache', function() {
        $run = Artisan::call('config:clear');
        $run = Artisan::call('cache:clear');
        $run = Artisan::call('config:cache');
        return 'FINISHED';  
    });

And then call the www.yourdomain.com/clear-cache route from your browser.


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


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


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.


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)

source


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.

I think this answer will help your problem.


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.


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


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


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

then I ran php artisan config:cache

This worked for me


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


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

I used Laravel 8, This is my solution

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

It's worked for me


Questions with php tag:

I am receiving warning in Facebook Application using PHP SDK Pass PDO prepared statement to variables Parse error: syntax error, unexpected [ Preg_match backtrack error Removing "http://" from a string How do I hide the PHP explode delimiter from submitted form results? Problems with installation of Google App Engine SDK for php in OS X Laravel 4 with Sentry 2 add user to a group on Registration php & mysql query not echoing in html with tags? How do I show a message in the foreach loop? Target class controller does not exist - Laravel 8 Message: Trying to access array offset on value of type null Array and string offset access syntax with curly braces is deprecated Visual Studio Code PHP Intelephense Keep Showing Not Necessary Error How to fix "set SameSite cookie to none" warning? The POST method is not supported for this route. Supported methods: GET, HEAD. Laravel Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? dyld: Library not loaded: /usr/local/opt/icu4c/lib/libicui18n.62.dylib error running php after installing node with brew on Mac What does double question mark (??) operator mean in PHP Post request in Laravel - Error - 419 Sorry, your session/ 419 your page has expired PHP with MySQL 8.0+ error: The server requested authentication method unknown to the client php mysqli_connect: authentication method unknown to the client [caching_sha2_password] Converting a POSTMAN request to Curl Composer require runs out of memory. PHP Fatal error: Allowed memory size of 1610612736 bytes exhausted Expected response code 250 but got code "530", with message "530 5.7.1 Authentication required Issue in installing php7.2-mcrypt Xampp localhost/dashboard How can I run specific migration in laravel How to change PHP version used by composer Laravel 5 show ErrorException file_put_contents failed to open stream: No such file or directory Artisan migrate could not find driver phpMyAdmin ERROR: mysqli_real_connect(): (HY000/1045): Access denied for user 'pma'@'localhost' (using password: NO) Ajax LARAVEL 419 POST error Laravel 5.5 ajax call 419 (unknown status) laravel 5.5 The page has expired due to inactivity. Please refresh and try again "The page has expired due to inactivity" - Laravel 5.5 How to increment a letter N times per iteration and store in an array? Can't install laravel installer via composer Only on Firefox "Loading failed for the <script> with source" Is there way to use two PHP versions in XAMPP? How to prevent page from reloading after form submit - JQuery laravel Eloquent ORM delete() method No Application Encryption Key Has Been Specified General error: 1364 Field 'user_id' doesn't have a default value How to logout and redirect to login page using Laravel 5.4? How to uninstall an older PHP version from centOS7 How to Install Font Awesome in Laravel Mix PDO::__construct(): Server sent charset (255) unknown to the client. Please, report to the developers Laravel - htmlspecialchars() expects parameter 1 to be string, object given How to downgrade php from 7.1.1 to 5.6 in xampp 7.1.1?

Questions with windows tag:

"Permission Denied" trying to run Python on Windows 10 A fatal error occurred while creating a TLS client credential. The internal error state is 10013 How to install OpenJDK 11 on Windows? I can't install pyaudio on Windows? How to solve "error: Microsoft Visual C++ 14.0 is required."? git clone: Authentication failed for <URL> How to avoid the "Windows Defender SmartScreen prevented an unrecognized app from starting warning" XCOPY: Overwrite all without prompt in BATCH Laravel 5 show ErrorException file_put_contents failed to open stream: No such file or directory how to open Jupyter notebook in chrome on windows Tensorflow import error: No module named 'tensorflow' git clone error: RPC failed; curl 56 OpenSSL SSL_read: SSL_ERROR_SYSCALL, errno 10054 bash: npm: command not found? Anaconda Installed but Cannot Launch Navigator AttributeError: module 'cv2.cv2' has no attribute 'createLBPHFaceRecognizer' How to install pandas from pip on windows cmd? 'ls' in CMD on Windows is not recognized Copy Files from Windows to the Ubuntu Subsystem Tensorflow r1.0 : could not a find a version that satisfies the requirement tensorflow Kill tomcat service running on any port, Windows python pip on Windows - command 'cl.exe' failed How to install pip3 on Windows? Mount current directory as a volume in Docker on Windows 10 Specifying Font and Size in HTML table Why Local Users and Groups is missing in Computer Management on Windows 10 Home? Command to run a .bat file How do I force Robocopy to overwrite files? Windows- Pyinstaller Error "failed to execute script " When App Clicked How to completely uninstall Android Studio from windows(v10)? Docker for Windows error: "Hardware assisted virtualization and data execution protection must be enabled in the BIOS" How do I kill the process currently using a port on localhost in Windows? Error : getaddrinfo ENOTFOUND registry.npmjs.org registry.npmjs.org:443 How to add a custom CA Root certificate to the CA Store used by pip in Windows? How to reset the use/password of jenkins on windows? npm ERR! Error: EPERM: operation not permitted, rename CMD (command prompt) can't go to the desktop Xampp-mysql - "Table doesn't exist in engine" #1932 Change drive in git bash for windows "OverflowError: Python int too large to convert to C long" on windows but not mac Visual studio code terminal, how to run a command with administrator rights? ImportError: cannot import name NUMPY_MKL Pip - Fatal error in launcher: Unable to create process using '"' Installing tensorflow with anaconda in windows Where does Anaconda Python install on Windows? PermissionError: [Errno 13] Permission denied How to restart a windows service using Task Scheduler How to install xgboost in Anaconda Python (Windows platform)? NPM stuck giving the same error EISDIR: Illegal operation on a directory, read at error (native) Can't access 127.0.0.1 anaconda - path environment variable in windows Global npm install location on windows?

Questions with laravel tag:

Parameter binding on left joins with array in Laravel Query Builder Laravel 4 with Sentry 2 add user to a group on Registration Target class controller does not exist - Laravel 8 Visual Studio Code PHP Intelephense Keep Showing Not Necessary Error The POST method is not supported for this route. Supported methods: GET, HEAD. Laravel How to fix 'Unchecked runtime.lastError: The message port closed before a response was received' chrome issue? Post request in Laravel - Error - 419 Sorry, your session/ 419 your page has expired Expected response code 250 but got code "530", with message "530 5.7.1 Authentication required How can I run specific migration in laravel Laravel 5 show ErrorException file_put_contents failed to open stream: No such file or directory Artisan migrate could not find driver Ajax LARAVEL 419 POST error Laravel 5.5 ajax call 419 (unknown status) laravel 5.5 The page has expired due to inactivity. Please refresh and try again "The page has expired due to inactivity" - Laravel 5.5 Can't install laravel installer via composer Laravel 5.4 Specific Table Migration laravel Eloquent ORM delete() method Including a css file in a blade template? laravel Unable to prepare route ... for serialization. Uses Closure Laravel 5.4 ‘cross-env’ Is Not Recognized as an Internal or External Command Vue js error: Component template should contain exactly one root element No Application Encryption Key Has Been Specified How to know Laravel version and where is it defined? General error: 1364 Field 'user_id' doesn't have a default value How to Install Font Awesome in Laravel Mix PHP7 : install ext-dom issue Laravel - htmlspecialchars() expects parameter 1 to be string, object given Laravel 5.4 create model, controller and migration in single artisan command Laravel Password & Password_Confirmation Validation Expected response code 250 but got code "535", with message "535-5.7.8 Username and Password not accepted Laravel: PDOException: could not find driver How to validate array in Laravel? Laravel Migration Error: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes Property [title] does not exist on this collection instance Composer: file_put_contents(./composer.json): failed to open stream: Permission denied Laravel Carbon subtract days from current date How to install all required PHP extensions for Laravel? if else condition in blade file (laravel 5.3) change the date format in laravel view page How to set the default value of an attribute on a Laravel model Extension gd is missing from your system - laravel composer Update laravel 5.3 new Auth::routes() The Response content must be a string or object implementing __toString(), "boolean" given after move to psql How to fix error Base table or view not found: 1146 Table laravel relationship table? "Please provide a valid cache path" error in laravel Setting selected option in laravel form Get only specific attributes with from Laravel Collection Get an image extension from an uploaded file in Laravel How to select specific columns in laravel eloquent

Questions with laravel-5 tag:

Expected response code 250 but got code "530", with message "530 5.7.1 Authentication required Laravel 5 show ErrorException file_put_contents failed to open stream: No such file or directory Can't install laravel installer via composer Including a css file in a blade template? No Application Encryption Key Has Been Specified How to Install Font Awesome in Laravel Mix Laravel Migration Error: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes Laravel 5.4 redirection to custom url after login How to set the default value of an attribute on a Laravel model laravel 5.3 new Auth::routes() The Response content must be a string or object implementing __toString(), "boolean" given after move to psql How to fix error Base table or view not found: 1146 Table laravel relationship table? "Please provide a valid cache path" error in laravel How to select specific columns in laravel eloquent How to clear Route Caching on server: Laravel 5.2.37 Laravel migration default value Where are logs located? SQLSTATE[HY000] [2002] Connection refused within Laravel homestead Laravel 5 PDOException Could Not Find Driver Laravel 5.2 - Use a String as a Custom Primary Key for Eloquent Table becomes 0 Eloquent ORM laravel 5 Get Array of ids Get environment value in controller How to redirect to a route in laravel 5 by using href tag if I'm not using blade or any template? Why do I have to run "composer dump-autoload" command to make migrations work in laravel? add new element in laravel collection object Laravel 5 Carbon format datetime How to query between two dates using Laravel and Eloquent? How to get client IP address in Laravel 5+ What is the difference between find(), findOrFail(), first(), firstOrFail(), get(), list(), toArray() Laravel 5: Retrieve JSON array from $request Change Timezone in Lumen or Laravel 5 Call to undefined function App\Http\Controllers\ [ function name ] How to get Current Timestamp from Carbon in Laravel 5 How to get All input of POST in Laravel ReflectionException: Class ClassName does not exist - Laravel Reloading .env variables without restarting server (Laravel 5, shared hosting) Response::json() - Laravel 5.1 How to access URL segment(s) in blade in Laravel 5? laravel 5 : Class 'input' not found Error 405 (Method Not Allowed) Laravel 5 Laravel Request getting current path with query string Laravel password validation rule How to set cookies in laravel 5 independently inside controller Laravel 5 – Clear Cache in Shared Hosting Server How to redirect back to form with input - Laravel 5 Laravel-5 'LIKE' equivalent (Eloquent) how to use php DateTime() function in Laravel 5 Can I do Model->where('id', ARRAY) multiple where conditions? How to set up file permissions for Laravel? Artisan, creating tables in database