Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

dipeshnx's avatar

/storage/ directory path

What is the recommended way of pointing Laravel to use different path for /storage/ directory?

0 likes
10 replies
fylzero's avatar

@dipeshnx php artisan storage:link

Creates a symlink from public to storage folder so it is publicly accessible.

Alternately, you can mod your config/filesystems.php under disks to point elsewhere.


    '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'),
        ],

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

    ],
24 likes
dipeshnx's avatar

Only effective solution I have seen so far is by doing the following:

  1. Add config in .env APP_STORAGE=/some/dir/path

  2. Add following in bootstrap/app.php $app->useStoragePath( env( 'APP_STORAGE', base_path() . '/storage' ) );

This solution seems dirty though.

1 like
dipeshnx's avatar

@fylzero I actually want to move /storage/ directory somewhere else in the filesystem not make it public.

fylzero's avatar

@dipeshnx Do this...

In .env...

LOCAL_STORAGE_PATH=/some/dir/path

In config/filesystems.php...

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

You can change this in the same way for public if you want.

In .env...

PUBLIC_STORAGE_ROOT=app/public/some/dir/path
PUBLIC_STORAGE_URL=app/public/some/dir/path

In config/filesystems.php...

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

Do this in the filesystems config. That is the right place for this change to happen.

25 likes
dipeshnx's avatar

It answered other question that I had in mind but still torn on the original question. I believe I didn't ask in right way.

Laravel stores logs, view caches, sessions, etc within /storage/framework/

If, for instance the application is installed at /var/project/, I would like Laravel to look for this /storage/ directory in some other location. For example, I want Laravel to use /tmp/storage/. And only way I can at the moment achieve that is by doing the following:

  1. Add config in .env APP_STORAGE=/some/dir/path
  2. Add following in bootstrap/app.php $app->useStoragePath( env( 'APP_STORAGE', base_path() . '/storage' ) );
1 like
fylzero's avatar

@dipeshnx With the solution I provided... you could add your own env LOCAL_STORAGE_PATH and aim that wherever you want on the server. Keep your filesystem driver as local in config and override that variable with an env variable. That should do what you want. Just make sure the directory you choose has the correct read/write permissions.

...and even if you need the files to be publicly accessible, you can just symlink to your public folder.

24 likes
ACH's avatar

@fylzero I tried your solution like this:

.env:

`LOCAL_STORAGE_PATH=~/var`

config/filesystems.php:

'disks' => [

        'local' => [
            'driver' => 'local',
            //'root' => env('LOCAL_STORAGE_PATH', storage_path('app')),
            'root' => env('LOCAL_STORAGE_PATH'),
...

I restart and start app: php artisan serv. After this nothing is stored in ~/var and log entries are still stored in storage/logs.

What am I doing wrong?

mikromike's avatar

@ACH, please check your setting from config/logging

      'single' => [
               'driver' => 'single',
               'path' => storage_path('logs/laravel.log'),
               'level' => env('LOG_LEVEL', 'debug'),
               'replace_placeholders' => true,
        ],

and replace

      'path' =>  env('LOCAL_STORAGE_PATH'). '/logs/laravel.log',

try this ?

Please or to participate in this conversation.