5

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?

miken32
  • 42,008
  • 16
  • 111
  • 154
Mic Jaw
  • 366
  • 2
  • 8
  • 1
    Perhaps this will be of help: https://mattstauffer.co/blog/extending-laravels-application - you could just swap out the path for `env(...)`. Haven't tested it though, so not sure if `env` is ready at that point. – Mike Rockétt Jun 13 '15 at 18:32

1 Answers1

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.

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',
        ],
    ],
];
MartinJH
  • 2,590
  • 5
  • 36
  • 49
  • 1
    This doesn't change the storage path for stuff like session/cache/etc. data though, I don't think? – ceejayoz Jun 18 '15 at 18:38
  • 1
    @ceejayoz Yup, you're right about that. The setup above only sets where file uploads are stored, such as .jpg and .mp4. You can set session storage path in `config/session.php`. – MartinJH Jun 18 '15 at 18:41
  • and cache in `config/cache.php` etc. :) – MartinJH Jun 18 '15 at 18:55