299

I duplicated a working laravel app and renamed it to use for another app. I deleted the vendor folder and run the following commands again:

composer self-update

composer-update

npm install

bower install

I configured my routes and everything properly however now when I try to run my app in my browser I get the following errors:

InvalidArgumentException in Compiler.php line 36: Please provide a valid cache path.

ErrorException in Filesystem.php line 111: file_put_contents(F:\www\example\app\storage\framework/sessions/edf262ee7a2084a923bb967b938f54cb19f6b37d): failed to open stream: No such file or directory

I have never had this issue before, I do not know what is causing it neither do I know how to fix it, I have googled online for a solution but have found none so far.

Daniel A. White
  • 187,200
  • 47
  • 362
  • 445
user3718908x100
  • 7,939
  • 15
  • 64
  • 123
  • 2
    You need to rebuild the storage folders, they are in your .gitignore file so wont be copied when you clone a project (as they are never pushed to the repo) – twigg Feb 08 '17 at 15:58

25 Answers25

871

Try the following:

create these folders under storage/framework:

  • sessions
  • views
  • cache

Now it should work

Novocaine
  • 4,692
  • 4
  • 44
  • 66
  • 37
    I combined this with php artisan cache:clear and php artisan config:clear and php artisan view:clear from the answer below and then it worked – cja Sep 25 '16 at 19:05
  • 2
    You can delete the storage folder manually and run the "php artisan storage:link" command via cmd. Then create folders as suggested above. Better you can keep the previous Storage folder as backup and later copy - paste the framework folder in new Storage path. – Niladri Banerjee - Uttarpara Aug 23 '17 at 12:36
  • I had exactly this issue and fix worked, was a result of deliberately excluding the entire framework folder from my subversion product due to its constant temporary file changing content. Then setting up the repro on a new system naturally resulted in these folders not existing. Thought I'd share... – AdamJones Jan 11 '18 at 13:45
  • 3
    git doesn't clone empty folders! I will create a file folder.keeper for those 3 folders. – Tiefan Ju Oct 28 '18 at 12:01
  • Yes, because don't need versioned this folders – Mauricio Wanderley Martins Oct 28 '18 at 12:33
  • A .gitkeep file in each directory would do the trick to prevent it to happen again – LTroya Dec 07 '18 at 16:44
  • 2
    also make sure to add "data" folder under cache to prevent having the following error "failed to clear cache. make sure you have the appropriate permissions" – karrar kazuya Feb 09 '21 at 18:29
  • Also make sure that if you changed the 'compiled' config value in `config/view.php` or the environment variable `VIEW_COMPILED_PATH` this directory also exists – Christian C Jul 26 '21 at 20:40
  • I solve this with this architecture: ```storage/framework/.gitignore storage/framework/cache storage/framework/cache/.gitignore storage/framework/sessions storage/framework/sessions/.gitignore storage/framework/testing storage/framework/testing/.gitignore storage/framework/views storage/framework/views/.gitignore ``` – OLIVIERS Oct 21 '21 at 10:46
  • on my case, i am missing the `views` folder. created it and it worked perfectly. thank you! `[+1]` – kapitan Apr 07 '22 at 00:53
  • View is the missing folder.I created manually and it worked perfectly. thank you! – Nashath Nasik May 05 '22 at 11:00
  • you also need the `framework/cache/data` subfolder – Ben Barreth May 31 '22 at 15:46
61

Try this:

  1. php artisan cache:clear
  2. php artisan config:clear
  3. php artisan view:clear
thefallen
  • 9,496
  • 2
  • 34
  • 49
60

Run these command to create required directories:

cd storage/
mkdir -p framework/{sessions,views,cache}
chmod -R 775 framework

That's it!

Ranjan Fadia
  • 1,363
  • 1
  • 14
  • 18
48

The cause of this error can be traced from Illuminate\View\Compilers\Compiler.php

public function __construct(Filesystem $files, $cachePath)
{
    if (! $cachePath) {
        throw new InvalidArgumentException('Please provide a valid cache path.');
    }

    $this->files = $files;
    $this->cachePath = $cachePath;
}

The constructor is invoked by BladeCompiler in Illuminate\View\ViewServiceProvider

/**
 * Register the Blade engine implementation.
 *
 * @param  \Illuminate\View\Engines\EngineResolver  $resolver
 * @return void
 */
public function registerBladeEngine($resolver)
{
    // The Compiler engine requires an instance of the CompilerInterface, which in
    // this case will be the Blade compiler, so we'll first create the compiler
    // instance to pass into the engine so it can compile the views properly.
    $this->app->singleton('blade.compiler', function () {
        return new BladeCompiler(
            $this->app['files'], $this->app['config']['view.compiled']
        );
    });

    $resolver->register('blade', function () {
        return new CompilerEngine($this->app['blade.compiler']);
    });
}

So, tracing back further, the following code:

$this->app['config']['view.compiled']

is generally located in your /config/view.php, if you use the standard laravel structure.

<?php
return [
    /*
    |--------------------------------------------------------------------------
    | View Storage Paths
    |--------------------------------------------------------------------------
    |
    | Most templating systems load templates from disk. Here you may specify
    | an array of paths that should be checked for your views. Of course
    | the usual Laravel view path has already been registered for you.
    |
    */
    'paths' => [
        resource_path('views'),
    ],
    /*
    |--------------------------------------------------------------------------
    | Compiled View Path
    |--------------------------------------------------------------------------
    |
    | This option determines where all the compiled Blade templates will be
    | stored for your application. Typically, this is within the storage
    | directory. However, as usual, you are free to change this value.
    |
    */
    'compiled' => realpath(storage_path('framework/views')),
];

realpath(...) returns false, if the path does not exist. Thus, invoking

'Please provide a valid cache path.' error.

Therefore, to get rid of this error, what you can do is to ensure that

storage_path('framework/views')

or

/storage/framework/views

exists :)

ghabx
  • 607
  • 5
  • 4
  • This one solves my issue. I'm creating a Laravel project but a backend only so I don't have anything to display like a view on my root route. – Maguzu Dec 21 '22 at 11:30
44

Ensure the below folders in storage directory:

  • logs
  • framework
  • framework/cache
  • framework/cache/data
  • framework/sessions
  • framework/testing
  • framework/views

Below is a command-line snippet that does for you

cd storage
mkdir logs
mkdir framework
mkdir framework/cache && framework/cache/data
mkdir framework/sessions
mkdir framework/testing
mkdir framework/views
chgrp -R www-data ../storage
chown -R www-data ../storage
user3785966
  • 2,578
  • 26
  • 18
  • Or: ``` export STORAGE_PATH='/path/tostorage/dir' mkdir -p ${STORAGE_PATH}/{logs,framework/{cache/data,sessions,testing,views}} chgrp -R www-data ${STORAGE_PATH} chown -R www-data ${STORAGE_PATH} ``` – imme Nov 27 '20 at 18:38
27

You can edit your readme.md with instructions to install your laravel app in other environment like this:

## Create folders

```
#!terminal

cp .env.example .env && mkdir bootstrap/cache storage storage/framework && cd storage/framework && mkdir sessions views cache

```

## Folder permissions

```
#!terminal

sudo chown :www-data app storage bootstrap -R
sudo chmod 775 app storage bootstrap -R

```

## Install dependencies

```
#!terminal

composer install

```
26

You need to create folders inside "framework". Please Follow these steps:

cd storage/
mkdir -p framework/{sessions,views,cache}

You also need to set permissions to allow Laravel to write data in this directory.

chmod -R 775 framework
chown -R www-data:www-data framework
Sohail Ahmed
  • 1,308
  • 15
  • 17
  • Can you please explain the command: `chown -R www-data:www-data framework` – Sourav Dutt Jul 23 '22 at 19:08
  • 1
    The chown command changes user ownership of a folder or file. command ```chown``` -R means recursive. www-data:www-data => username:group assigning to framework folder. You will have complete detail about chown command. https://phoenixnap.com/kb/linux-chown-command-with-examples – Sohail Ahmed Jul 23 '22 at 19:37
18

Try the following:

create these folders under storage/framework:

  • sessions
  • views
  • cache/data

if still it does not work then try

php artisan cache:clear
php artisan config:clear
php artisan view:clear

if get an error of not able to clear cache. Make sure to create a folder data in cache/data

Mohsin Younas
  • 324
  • 4
  • 12
12
  1. Start by clearing the cache
php artisan cache:clear
php artisan config:clear
php artisan view:clear
  1. If it doesn't work, ensure the all the following folders are available
logs
framework
framework/cache 
framework/sessions 
framework/views
  1. If none of the suggestions works, verify that the config file config/view.php is present. If not, you can get a copy of this file for the Laravel you're using and copy it to the project config folder.
11

My 2 cents

Remove everything inside storage and then do this:

> cd storage/
> mkdir -p framework/{sessions,views,cache}
> chmod -R 755 framework

// This last line depends on your user group settings so 
// it may not be applicable to you.
> chown -R www-data:www-data framework

Worked for me =)

0xe1λ7r
  • 1,957
  • 22
  • 31
10

Check if the following folders exists, if not create these folders.

  • storage/framework/cache
  • storage/framework/sessions
  • storage/framework/testing
  • storage/framework/views
rfkortekaas
  • 6,049
  • 2
  • 27
  • 34
RAMA KRISHNA
  • 101
  • 1
  • 3
8

I solved the problem when I created framework folder inside storage folder and its subfolders sessions, views and cache.

Go to your cmd or terminal then type your project root path and after that type the following:

cd storage
mkdir framework
cd framework
mkdir sessions
mkdir views
mkdir cache

Go to your project root path back again and run composer update

After that artisan works perfectly.

borisoft82
  • 79
  • 1
  • 4
7

Step 1、Create these folders

  • mkdir -p storage/{app,framework,logs}
  • mkdir -p storage/framework/{sessions,views,cache}
  • chmod -R 777 storage

Step 2、Clear cache/config/view

  • php artisan cache:clear
  • php artisan config:clear
  • php artisan view:clear
Tansy Z
  • 169
  • 2
  • 2
  • 2
    Do not, under any circumstances, give full write access to all users on a system, which is what you are doing here with `chmod -R 777`. THIS IS AN INVITATION TO BE HACKED, as your web server process user can now write there too. – Martijn Pieters Apr 10 '22 at 10:42
5

step 1 : php artisan storage:link

step 2 : create these folders inside storage folder

Ensure the below folders in storage directory:

logs
framework
framework/cache 
framework/sessions 
framework/views

It worked for me

Rashid Iqbal
  • 840
  • 10
  • 14
3

Please run in terminal,

   sudo mkdir storage/framework
   sudo mkdir storage/framework/sessions
   sudo mkdir storage/framework/views
   sudo mkdir storage/framework/cache
   sudo mkdir storage/framework/cache/data

Now you have to change permission,

   sudo chmod -R 777 storage
  • If you want create dynamically, you can also create as, `$paths = ["storage","storage/framework", "storage/framework/sessions", "storage/framework/views", "storage/framework/cache", "storage/framework/cache/data", "storage/logs", "storage/fonts"];` ` foreach( $paths as $path){` ` if (!File::isDirectory($path)) { ` `File::makeDirectory($path, 0777, true, true);` `}` `}` – Md Rasheduzzaman Jan 15 '20 at 07:47
  • 1
    Do not, under any circumstances, give full write access to all users on a system, which is what you are doing here with `chmod -R 777`. THIS IS AN INVITATION TO BE HACKED, as your web server process user can now write there too. – Martijn Pieters Apr 05 '22 at 21:44
1

Issue on my side(while deploying on localhost): there was views folder missing.. so if you have don't have the framework folder the you 'll need to add folders. but if already framework folder exist then make sure all above folders i.e 1. cache 2. session 3. views

exists in your framework directory.

Farid Abbas
  • 294
  • 4
  • 5
1

If this happens on server:

sudo mkdir logs framework framework/cache framework/sessions framework/views
sudo chgrp -R www-data storage
sudo chmod -R ug+rwx storage
Ostap Brehin
  • 3,240
  • 3
  • 25
  • 28
0

I solved this problem by adding this line in my index.php:

$app['config']['view.compiled'] = "storage/framework/cache";
Cà phê đen
  • 1,883
  • 2
  • 21
  • 20
crius
  • 23
  • 1
  • 4
0

Your storage directory may be missing, or one of its sub-directories. The storage directory must have all the sub-directories that shipped with the Laravel installation.

Das_Geek
  • 2,775
  • 7
  • 20
  • 26
Naveed Ali
  • 361
  • 3
  • 12
0

May be the storage folder doesn't have the app and framework folder and necessary permission. Inside framework folder it contains cache, sessions, testing and views. use following command this will works.

Use command line to go to your project root: 
cd {your_project_root_directory}
Now copy past this command as it is: 
cd storage && mkdir app && cd app && mkdir public && cd ../ && mkdir framework && cd framework && mkdir cache && mkdir sessions && mkdir testing && mkdir views && cd ../../ && sudo chmod -R 777 storage/

I hope this will solve your use.

Sujon Chondro Shil
  • 105
  • 1
  • 2
  • 10
  • Do not, under any circumstances, give full write access to all users on a system, which is what you are doing here with `chmod -R 777`. THIS IS AN INVITATION TO BE HACKED, as your web server process user can now write there too. – Martijn Pieters Apr 05 '22 at 21:45
0

I also had a similar case after copying a project on a production server. The public folder was accessed by Apache via a symbolic link.

For Apache or the PHP service, the path to the project has not changed, thus they used cached file paths that lead to the old project repository.

Restarting Apache and PHP service resolved the issue.

Karkan
  • 126
  • 2
  • 9
0

step 1 : php artisan storage:link

step 2 : create these folders inside storage folder

Ensure the below folders in storage directory:

logs framework framework/cache framework/sessions framework/views It worked for me

This worked for me too

0

In my case, the config cache files are all missing in boostrap/cache... so solution to me is php artisan config:cache to re-create cache files at boostrap/cache.

free2idol1
  • 174
  • 1
  • 3
  • 12
0

You only have to do is replace your laravel project Storage folder to another laravel project Storage folder and you resolve that issue simple!

-5

Error :'Please provide a valid cache path.' error.

If these type error comes then the solution given below :-

please create data folder inside storage/framework/cache

  • 2
    Welcome to Stack Overflow! Please provide answers that include not just the solution, but at least a few words about how you found this out. – new Q Open Wid May 06 '20 at 14:39