存储路径不是公共路径的一部分(Laravel 8)

Posted

技术标签:

【中文标题】存储路径不是公共路径的一部分(Laravel 8)【英文标题】:Storage path is not part of public path (Laravel8) 【发布时间】:2022-01-21 08:36:44 【问题描述】:

我正在使用 laravel 8,但出现存储错误:

"存储路径 /var/www/type.adoreanime.com/htdocs/Linkati/storage/app 不是一部分 公共路径/var/www/type.adoreanime.com/htdocs/Linkati/public (看法: /var/www/type.adoreanime.com/htdocs/Linkati/resources/views/layouts/master.blade.php) (看法: /var/www/type.adoreanime.com/htdocs/Linkati/resources/views/layouts/master.blade.php) (看法: /var/www/type.adoreanime.com/htdocs/Linkati/resources/views/layouts/master.blade.php) ◀"

我运行 nginx 作为我的网络服务器,所以我将 /var/www/type.adoreanime.com/htdocs/Linkati/public 设置为根目录。

文件系统.php

<?php

return [

    /*
    |--------------------------------------------------------------------------
    | Default Filesystem Disk
    |--------------------------------------------------------------------------
    |
    | Here you may specify the default filesystem disk that should be used
    | by the framework. The "local" disk, as well as a variety of cloud
    | based disks are available to your application. Just store away!
    |
    */

    'default' => env('FILESYSTEM_DRIVER', 'local'),

    /*
    |--------------------------------------------------------------------------
    | Default Cloud Filesystem Disk
    |--------------------------------------------------------------------------
    |
    | Many applications store files both locally and in the cloud. For this
    | reason, you may specify a default "cloud" driver here. This driver
    | will be bound as the Cloud disk implementation in the container.
    |
    */

    'cloud' => env('FILESYSTEM_CLOUD', 's3'),

    /*
    |--------------------------------------------------------------------------
    | Filesystem Disks
    |--------------------------------------------------------------------------
    |
    | Here you may configure as many filesystem "disks" as you wish, and you
    | may even configure multiple disks of the same driver. Defaults have
    | been setup for each driver as an example of the required options.
    |
    | Supported Drivers: "local", "ftp", "sftp", "s3", "rackspace"
    |
    */

    'disks' => [

        'local' => [
            'driver' => 'local',
            'root' => storage_path('app'),
        ],

        'public' => [
            'driver' => 'local',
            'root' => storage_path('app/public'),
            'url' => env('APP_URL') . '/storage',
            'visibility' => 'public',
        ],

        's3' => [
            'driver' => 's3',
            'key' => env('AWS_ACCESS_KEY_ID'),
            'secret' => env('AWS_SECRET_ACCESS_KEY'),
            'region' => env('AWS_DEFAULT_REGION'),
            'bucket' => env('AWS_BUCKET'),
            'url' => env('AWS_URL'),
        ],

        's3_public' => [
            'driver' => 's3',
            'key' => env('AWS_ACCESS_KEY_ID'),
            'secret' => env('AWS_SECRET_ACCESS_KEY'),
            'region' => env('AWS_DEFAULT_REGION'),
            'bucket' => env('AWS_BUCKET'),
            'url' => env('AWS_URL'),
            'visibility' => 'public',
        ],

    ],

];

有人知道如何解决这个问题吗?

【问题讨论】:

您是否运行php artisan storage:link 命令在您的公共目录中生成符号链接? @Rwd 我刚试过,但错误仍然存​​在 你在使用 Spatie 媒体库吗? @Rwd 是的,我正在使用它 这可能会有所帮助:github.com/spatie/laravel-medialibrary/issues/… 【参考方案1】:

您的目录结构可能设置不正确。你的 htdocs 目录应该是 laravel 的 /public 目录,如果你用 storage:link 链接它,它与 storage/app/public 是同一个目录。您似乎在 htdocs 中有 laravel 根文件夹。

无论是什么导致了错误,它试图访问存储/应用程序,而不是存储/应用程序/公共。前者不应该在您的服务器上可见。

【讨论】:

以上是关于存储路径不是公共路径的一部分(Laravel 8)的主要内容,如果未能解决你的问题,请参考以下文章

php 在Laravel 5.5中更改公共路径

如何摆脱 laravel on wamp 中的公共路径

在 Laravel 中将 Public 添加到资产路径

Laravel 默认存储路径更改

将图像保存在公共文件夹中,而不是存储 laravel 5

App Engine 上的 Laravel 8:“请提供有效的缓存路径”