File and Folder Permission on an external disc are invalid

I’m not sure if this is a setup problem or a bug, so any help is welcome:

I’ve multiple environments with my website. While dev and staging write the uploads in the storage/app/uploads directory, prod is configured with an external disc in the filesystems


        'uploads' => [
            'driver' => (env('APP_ENV') === "prod") ? 'sftp' : 'local',
            'root' => (env('APP_ENV') === "prod")
                ? env('UPLOADS_ROOT')
                : storage_path('app/uploads'),
            'url' => (env('APP_ENV') === "prod")
                ? env('UPLOADS_URL')
                : '/storage/app/uploads',

            # Only used on sftp driver
            'host' => env('UPLOADS_HOST'),
            'port' => (int) env('UPLOADS_PORT'),
            'username' => env('UPLOADS_USERNAME'),
            'password' => env('UPLOADS_PASSWORD'),

            # Probably only local
            'visibility' => 'public',
            'throw' => false,

While the folders and files are written with 755 and 644 in the storage/app folder, they’re written with 700 and 644 on the external drive which leads to accessability problems of those uploads (or visibility problems if it’s for images).

I’ve this here in the .env, too:


Any idea why this could happen?

Thanks for the support already :slight_smile:

EDIT: I also recognized that the file paths are wrong if you quote the FOLDER and FILE_MASK in the .env with single quotes. That’s definitly strange o_O

The external drive may need a “umask” set, which is the default permissions for newly created files and folders. This is outside the scope of Laravel’s filesystem drivers.

1 Like

It wasnt umask. I tested it on and on, folders which were created directly via SFTP were set correctly so I started searching for this issue in relation with Flysystem and found this issue:

One member posted a working solution:

Actually, this is because Flysystem v3 is a bit stricter on directory permissions and has private visibility for directories by default. The files will also still be accessible. I tried that with setting the public storage link and put the directory and the file in the storage/app/public directory and I was able to access the file through the web. It doesn’t matter if the directory is private.

You can set a separate 'directory_visibility' => 'public', in your disk config if you want.

I added this to my filesystem config file and the problem was gone.

Here’s some more info about this:

I hope this might help somebody in the future :wink:

1 Like