在Laravel 5.1中使用.env设置存储路径

时间:2022-10-18 18:07:15

I want to configure the storage path in a Laravel 5.1 using the .env file. My bootstrap/app.php looks like this:

我想使用.env文件配置Laravel 5.1中的存储路径。我的引导/应用程序。php是这样的:

<?php
$app = new \Illuminate\Foundation\Application(
    realpath(__DIR__.'/../')
);
$app->useStoragePath(getenv('STORAGE_PATH'));

and the relevant line in .env file is:

而.env文件中的相关行为:

STORAGE_PATH=/var/www/storage

This doesn't work. I figured out the Dotenv library is initialised after the bootstrap is processed so the .env variables are not available in bootstrap.php.

这并不工作。我发现Dotenv库是在处理引导之后初始化的,所以.env变量在bootstrap.php中不可用。

Is there a different place where I can set the storage path and the .env variables are available?

是否有一个不同的地方我可以设置存储路径和。env变量?

1 个解决方案

#1


3  

In config/filesystems.php you can set your storage path. Try setting your storage path there and see if it works. Note that the example below is my suggestion as to how your config/filesystems.php should look. Don't mind the s3 setup. That's a part of my project.

在config /文件系统。php可以设置存储路径。试着在那里设置你的存储路径,看看它是否有效。注意,下面的示例是我关于配置/文件系统的建议。php应该。不要介意s3设置。这是我项目的一部分。

Remember to remove $app->useStoragePath(getenv('STORAGE_PATH')); from app.php

记得删除应用程序- > useStoragePath美元(getenv(' STORAGE_PATH '));从app.php

return [

    'default' => 's3',

    'cloud' => 's3',

    'disks' => [

        'local' => [
            'driver' => 'local',
            'root'   => env('STORAGE_PATH'),
        ],

        's3' => [
            'driver' => 's3',
            'key'    => env('AWS_KEY'),
            'secret' => env('AWS_SECRET'),
            'region' => env('AWS_REGION'),
            'bucket' => env('AWS_BUCKET'),
        ],

        'rackspace' => [
            'driver'    => 'rackspace',
            'username'  => 'your-username',
            'key'       => 'your-key',
            'container' => 'your-container',
            'endpoint'  => 'https://identity.api.rackspacecloud.com/v2.0/',
            'region'    => 'IAD',
        ],
    ],
];

#1


3  

In config/filesystems.php you can set your storage path. Try setting your storage path there and see if it works. Note that the example below is my suggestion as to how your config/filesystems.php should look. Don't mind the s3 setup. That's a part of my project.

在config /文件系统。php可以设置存储路径。试着在那里设置你的存储路径,看看它是否有效。注意,下面的示例是我关于配置/文件系统的建议。php应该。不要介意s3设置。这是我项目的一部分。

Remember to remove $app->useStoragePath(getenv('STORAGE_PATH')); from app.php

记得删除应用程序- > useStoragePath美元(getenv(' STORAGE_PATH '));从app.php

return [

    'default' => 's3',

    'cloud' => 's3',

    'disks' => [

        'local' => [
            'driver' => 'local',
            'root'   => env('STORAGE_PATH'),
        ],

        's3' => [
            'driver' => 's3',
            'key'    => env('AWS_KEY'),
            'secret' => env('AWS_SECRET'),
            'region' => env('AWS_REGION'),
            'bucket' => env('AWS_BUCKET'),
        ],

        'rackspace' => [
            'driver'    => 'rackspace',
            'username'  => 'your-username',
            'key'       => 'your-key',
            'container' => 'your-container',
            'endpoint'  => 'https://identity.api.rackspacecloud.com/v2.0/',
            'region'    => 'IAD',
        ],
    ],
];