laravel 请提供有效的缓存路径

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/38483837/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 17:28:07  来源:igfitidea点击:

Please provide a valid cache path

laravellaravel-5.2

提问by user3718908

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:

我复制了一个可用的 Laravel 应用程序并将其重命名为用于另一个应用程序。我删除了供应商文件夹并再次运行以下命令:

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

Compiler.php 第 36 行中的 InvalidArgumentException:请提供有效的缓存路径。

Filesystem.php 第 111 行中的 ErrorException:file_put_contents(F:\www\example\app\storage\framework/sessions/edf262ee7a2084a923bb967b938f54cb19f6b37d):无法打开流:没有这样的文件或目录

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.

我以前从未遇到过这个问题,我不知道是什么导致了它,也不知道如何解决它,我在网上用谷歌搜索了一个解决方案,但到目前为止还没有找到。

采纳答案by user3718908

So apparently what happened was when I was duplicating my project the framework folder inside my storage folder was not copied to the new directory, this cause my error.

很明显,当我复制我的项目时,我的存储文件夹中的框架文件夹没有复制到新目录中,这导致了我的错误。

回答by Mauricio Wanderley Martins

Try the following:

请尝试以下操作:

create these folders under storage/framework:

存储/框架下创建这些文件夹

  • sessions
  • views
  • cache
  • sessions
  • views
  • cache

Now it should work

现在它应该工作

回答by thefallen

Try this:

尝试这个:

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

回答by Alex B. Santos

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

您可以编辑您的readme.md,并附上在其他环境中安装 Laravel 应用程序的说明,如下所示:

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

```

回答by ghabx

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

这个错误的原因可以从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

构造函数由BladeCompiler在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.

如果您使用标准的 Laravel 结构,通常位于您的 /config/view.php 中。

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

realpath(...)返回 false,如果路径不存在。因此,调用

'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 :)

存在:)

回答by Sohail Ahmed

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.

您还需要设置权限以允许 Laravel 在此目录中写入数据。

chmod -R 775 framework
chown -R www-data:www-data framework

回答by Rasheduzzaman

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

回答by Weber

I solved the problem when I created frameworkfolder inside storagefolder and its subfolders sessions, viewsand cache.

当我在存储文件夹及其子文件夹sessionviewscache 中创建框架文件夹时,我解决了这个问题。

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

转到您的 cmd 或终端,然后输入您的项目根路径,然后输入以下内容:

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

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

再次回到您的项目根路径并运行composer update

After that artisan works perfectly.

在那之后,工匠完美地工作。

回答by Mohsin Younas

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

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

如果出现无法清除缓存的错误。确保在缓存/数据中创建文件夹数据

回答by Farid Abbas

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

我这边的问题(在本地主机上部署时):缺少视图文件夹..所以如果你没有框架文件夹,你需要添加文件夹。但如果框架文件夹已经存在,那么请确保以上所有文件夹,即 1. 缓存 2. 会话 3. 视图

exists in your framework directory.

存在于您的框架目录中。