title: "storage/logs/laravel-2019-11-22.log" could not be opened: failed to open stream: Permission denied
body: <p>I got the following error when entering my site on a production server:</p>
  
  <blockquote>
    <p>The stream or file "/var/app/current/storage/logs/laravel-2019-11-22.log" could not be opened: failed to open stream: Permission denied</p>
  </blockquote>
  
  <p>I tried running the following commands and got Permisions denied in the terminal:</p>
  
  <pre><code>php artisan cache:clear
  php artisan config:clear
  php artisan config:cache
  php artisan optimize:clear
  </code></pre>
  
  <p>I ran <code>chmod -R 775 storage/logs/</code> and <code>composer dump-autoload</code> and I was able to get onto the home page of my site without any errors. After surfing around the site a bit more I was getting the same error in various areas and not in others: </p>
  
  <p><strong>Again same error</strong></p>
  
  <blockquote>
    <blockquote>
      <p>The stream or file "/var/app/current/storage/logs/laravel-2019-11-22.log" could not be opened: failed to open stream: Permission denied</p>
    </blockquote>
  </blockquote>
  
  <p>I deleted the following files and ran <code>php artisan cahce:clear</code>:</p>
  
  <pre><code>/bootstrap/cache/packages.php
  /bootstrap/cache/services.php
  /bootstrap/cache/config.php.php
  </code></pre>
  
  <p>The only other advice I've seen is run:</p>
  
  <pre><code>sudo chmod -R 777 storage/*
  </code></pre>
  
  <p>Which seems like a bad idea on a production server, but seems to be upvoted answer. Should I just give my storage director 777 permissions and why? Is there another way of fixing this? </p>
  
  <p><strong>Edit:</strong></p>
  
  <p>I'm trying to do this as stated here:</p>
  
  <pre><code>// set current user as owner and the webserver user as the group
  sudo chown -R $USER:www-data storage
  sudo chown -R $USER:www-data bootstrap/cache
  // set directory permission to be 775
  chmod -R 775 storage
  chmod -R 775 bootstrap/cache
  </code></pre>
  
  <p>but when I run <code>sudo chown -R $USER:www-data storage</code> I get this error:</p>
  
  <blockquote>
    <p>chown: invalid group: ‘myusername:www-data’</p>
  </blockquote>