LoginSignup
14
14

More than 5 years have passed since last update.

Laravel の Storage::put などで作成されるディレクトリのパーミッション設定

Last updated at Posted at 2018-07-27

やりたいこと

LaravelがStorage::put等で作成するディレクトリのパーミッションを775にしたかったのですが、
実行ユーザのumaskを002にしても、作成されるディレクトリのパーミッションが755のままでした。

結論としては、設定ファイルで変更できたのですが、Laravelのソースコードを追っていたりして結構手間取ってしまいました。
探し方が悪かったのか、Laravelドキュメントに該当の項目を見つけられなかったのでメモしておきます。

結論

driverlocal なディスク上に作成されるディレクトリ、ファイルのパーミッションは
filesystems.php設定ファイルで変更することができます。

設定例

下記の設定例のようにpermissions設定値を追記してください

/config/filesystems.php
/*
|--------------------------------------------------------------------------
| Filesystem Disks
|--------------------------------------------------------------------------
|
| Here you may configure as many filesystem "disks" as you wish, and you
| may even configure multiple disks of the same driver. Defaults have
| been setup for each driver as an example of the required options.
|
| Supported Drivers: "local", "ftp", "s3", "rackspace"
|
*/

'disks' => [

    'local' => [
        'driver' => 'local',
        'root' => storage_path('app'),
        'permissions' => [ // permissions 設定値を追記
            'dir' => [
                'public'  => 0775, // public なディレクトリは775で作成 
            ],
            'file' => [
                'public' => 0664, // public なファイルは664で作成
            ],
        ]
    ],
...(以下略)

確認

artisan tinker で動作確認してみます

$ php artisan tinker
Psy Shell v0.9.6 (PHP 7.2.6 — cli) by Justin Hileman
>>> \Storage::put('test/file', 'hoge');
=> true
>>> exit
Exit:  Goodbye
$ ls -l storage/app | grep test
drwxrwsr-x 2 vagrant www-data   17 Jul 27 10:36 test
$ ls -l storage/app/test/file
-rw-rw-r-- 1 vagrant www-data 4 Jul 27 10:36 storage/app/test/file

設定が参照されている箇所

時間のある方は、下記のソースを追ってみると楽しいと思います。

./vendor/laravel/framework/src/Illuminate/Filesystem/FileSystemManager.php
./vendor/league/flysystem/src/Adapter/Local.php

14
14
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
14
14