title: Laravel 5.7 Nginx 500 error when accessing pages, possible storage permission issues?
body: <p>SOLVED
  Hi I am deploying my first Laravel application to DigitalOcean and I'm getting a 500 error when trying to access the url. Let me start by saying this is my first Laravel and Nginx deployment and my first time configuring a web server so if you see something that is wrong I welcome the feedback! I know I can use Forge but I'm trying to learn so bear with me.</p>
  
  <p>The server consists of the following:</p>
  
  <ul>
  <li>Ubuntu 18.04</li>
  <li>Nginx 1.14.0</li>
  <li>PHP 7.2.7</li>
  <li>Laravel 5.6</li>
  </ul>
  
  <p>Here is my Nginx config file (I changed the SSL paths to path_to and my url to sub.domain.com for security reasons):</p>
  
  <pre><code>server {
          listen 80;
  
          root /var/www/sub.domain.com/public;
  
          add_header X-Frame-Options "SAMEORIGIN";
          add_header X-XSS-Protection "1; mode=block";
          add_header X-Content-Type-Options "nosniff";
  
          index index.php index.html index.htm index.nginx-debian.html;
  
          charset utf-8;
  
          location / {
                  try_files $uri $uri/ /index.php$query_string;
          }
  
          location ~ \.php$ {
                  fastcgi_split_path_info ^(.+\.php)(/.+)$;
                  include fastcgi_params;
                  include snippets/fastcgi-php.conf;
                  fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
          }
  
          location ~ /\.ht {
                  deny all;
          }
  
          location = /favicon.ico { access_log off; log_not_found off; }
          location = /robots.txt  { access_log off; log_not_found off; }
  
          error_page 404 /index.php;
  
          listen 443 ssl; # managed by Certbot
          ssl_certificate /path_to/sub.domain.com/fchain.pem$
          ssl_certificate_key /path_to/sub.domain.com/pkey.p$
          include /path_to/options-ssl-nginx.conf; # managed by Certbot
          ssl_dhparam /path_to/ssl-dhparams.pem; # managed by Certbot
  }
  server {
      if ($host = www.sub.domain.com) {
          return 301 https://$host$request_uri;
      } # managed by Certbot
  
      if ($host = sub.domain.com) {
          return 301 https://$host$request_uri;
      } # managed by Certbot
  
      listen 80;
      server_name sub.domain.com www.sub.domain.com;
      return 404; # managed by Certbot
  }
  </code></pre>
  
  <p>I have a storage folder with a symbolic link to public/storage on my localhost. I have several folders inside storage/app/public, however when I cloned my project to the server none of those folders transferred over and the symbolic link appeared to be missing as there was no storage folder in the public folder. So I ran <code>php artisan storage:link</code> and now I have public/storage. I'm assuming I just have to recreate the directories inside storage/app/public.</p>
  
  <p>When I try to access my url I get a 500 error and this is the error from Nginx:</p>
  
  <pre><code> *111 FastCGI sent in stderr: "PHP message: PHP Fatal error:  Uncaught ErrorException: file_put_contents(/var/www/sub.domain.com/storage/framework/views/7315ddb3840f197f8140b159965a4ba4b98e33fe.php): failed to open stream: Permission denied in /var/www/sub.domain.com/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php:122
  </code></pre>
  
  <p>After doing a little research I found an article that said I needed to change the permissions for the storage folder so I ran the following two commands:</p>
  
  <pre><code>sudo chmod -R o+w storage/
  sudo chmod -R 775 storage/
  </code></pre>
  
  <p>Unfortunately this didn't solve my issue. It also mentioned changing the permissions for a bootstrap file but I'm not sure what this is referring to.  I am unsure if this is an issue with my Nginx config file (I've changed it multiple times) or if it's a permission issue. I'm guessing it's a permission issue due to the error I'm getting.</p>
  
  <p>I appreciate any help! Thanks!</p>