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

javierldb's avatar

File Storage outside Laravel folder

Is it possible to create a local disk to store files, outside the /storage folder within Laravel root directory? In my case I want to store the files on a secondary disk on the same server:

Update: This is an entry in filesystem.php 'MyApp' => [ 'driver' => 'local', 'root' => storage_path('/opt/MyApp/files'), ],

But this stored the files in <laravel_app_path>/storage/opt/MyApp/files. Not what I needed.

Thanks.

1 like
10 replies
jeffreyvanrossum's avatar

I think you can, but you shouldn't use the storage_path helper in that case.

1 like
Snapey's avatar

Create a new 'disk' in the filesystems.php config file. Either set it as the default, or specify it each time you perform any disk actions.

The files in the disk won't be publicly accessible unless you manually create a symlink

javierldb's avatar

Hi @snapey , the code from my first post was from the filesystems.php file. I do have two drives defined, but apparently the "root" has to be the /storage folder.

Snapey's avatar
Snapey
Best Answer
Level 122

No, the 'root' can be any folder - including non-local (S3)

using storage_path is limiting you to that folder. The base_path() function returns your project root

'MyApp' => [
    'driver' => 'local',
    'root' => base_path('/files'), 
],

or, anywhere in your operating system;

'MyApp' => [
    'driver' => 'local',
    'root' => '/opt/MyApp/files', 
],
7 likes
mecjos's avatar

I need to set this local driver according to user preference. Is it possible to make it dynamic?

javierldb's avatar

@snapey Awesome, that's what I needed. Would you point me to the right doc for that? I'm used to https://laravel.com/docs, but I feel there's gotta be some other place when I can dig more these options and helpers. Thank you very much.

GiovanniSF's avatar

A more complete and in depth documentation on Laravel can be found in https://laravel.com/api/7.x/index.html

It can be very useful to read some important (and well documented) classes and dive even deeper, like vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php

1 like
Snapey's avatar

ideally you would move this to an env config element so that you can have different paths in development and production without changing the code base.

2 likes

Please or to participate in this conversation.