title: Laravel Storage Framework and Log File/Folder Permissions Issue
body: <p>I'm having an issue with Laravel's file/folder permissions when they are generated from different sources. This may be a bit long winded, but bear with me.</p>
  
  <p><strong>Scenario</strong></p>
  
  <p>1) An <code>artisan</code> command, called <code>TestCommand.php</code>, triggered via <code>php artisan test:command</code> has the following code:</p>
  
  <pre><code>public function handle(){
    \Log::info("Test Command Executed from Command Line");
  }
  </code></pre>
  
  <p>2) A Contoller Function in <code>TestController.php</code>, triggered when accessing <code>http://localhost/test</code>, which has the following code:</p>
  
  <pre><code>public function test(){
    \Log::info("Test Command Executed from Web View");
  }
  </code></pre>
  
  <p>Both functions work correctly when triggered individually, <strong>but as soon as one is triggered, the other will not work,</strong> as the generated log file in <code>storage/logs</code> now has incorrect permissions, user and/or group. </p>
  
  <p><strong>Situation 1</strong></p>
  
  <p>If I run <code>php artisan test:command</code>, I get the following log file:</p>
  
  <pre><code>-rw-r--r-- | 1 | tim | wheel | 76B | 25 Aug 14:03 | laravel-2017-08-25.log
  </code></pre>
  
  <p>And navigating to <code>http://localhost/test</code> returns the following error:</p>
  
  <blockquote>
    <p>This page isn’t working</p>
    
    <p>localhost is currently unable to handle this request.</p>
    
    <p>HTTP ERROR 500</p>
  </blockquote>
  
  <p>No Laravel stack trace ("Woops, something went wrong") is displayed, as that only happens following writing to the Laravel logs.</p>
  
  <p><strong>Situation 2</strong></p>
  
  <p>If I navigate to <code>http://localhost/test</code> first, I get this log file:</p>
  
  <pre><code>-rw-r--r-- | 1 | _www | wheel | 72B | 25 Aug 14:06 | laravel-2017-08-25.log
  </code></pre>
  
  <p>And running the <code>php artisan test:command</code> returns the following:</p>
  
  <blockquote>
    <p>PHP Fatal error:  Uncaught exception 'UnexpectedValueException' with message 'The stream or file ".../storage/logs/laravel-2017-08-25.log" could not be opened: failed to open stream: Permission denied' in .../vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php:97
    Stack trace: ...</p>
  </blockquote>
  
  <p><strong>Conclusion</strong></p>
  
  <p>Notice the user is now <code>_www</code> instead of <code>tim</code>, which is to be expected given the generation source of the file in <code>storage/logs</code>. Retroactively, this can be fixed quite easily by running:</p>
  
  <pre><code>sudo chmod -R 777 storage/logs
  </code></pre>
  
  <p>But that's not a good solution for a number of reasons:</p>
  
  <ul>
  <li>777 is a bad idea for production web servers, and 755 doesn't seem to work for my configuration.</li>
  <li>Any time a new file is created (daily for logs, any time for files in <code>storage/framework/*</code>, etc) this command would need to be run again.</li>
  <li>I don't have direct access to the webserver where this command would have to be run x number of times per day, meaning I would have to bug someone else to do it.</li>
  </ul>
  
  <p>Given all this, how do I unify the files to allow either source to create the file and then modify the file as needed?</p>
  
  <p>Webserver is apache, dev environment is Mac, production is linux</p>
  
  <p><strong>Update</strong></p>
  
  <p>I think a good solution is to have <code>tim</code> and <code>_www</code> in the same group, and assign <code>storage/logs</code> to that group using </p>
  
  <pre><code>chgrp -R &lt;user_group&gt; storage
  </code></pre>
  
  <p>But then the next issue is that by default, the permissions on any generated folder in Laravel is <code>644</code>, which doesn't allow write access by the <code>group</code>, only read.</p>
  
  <p>Will look into modifying this if possible.</p>