Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Storage path set using .env in Laravel 5.1

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

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

and the relevant line in .env file is:

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.

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

like image 948
Mic Jaw Avatar asked Oct 20 '22 09:10

Mic Jaw


1 Answers

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.

Remember to remove $app->useStoragePath(getenv('STORAGE_PATH')); from 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',
        ],
    ],
];
like image 134
MartinJH Avatar answered Oct 22 '22 00:10

MartinJH