title: Laravel + NGINX giving 403 forbidden
body: <p>I am really stuck loading a Laravel app for the first time on the web (EC2). </p>
  
  <p>I have an instance of Ubuntu 18.04 running latest laravel 5.6. I have been stuck for hours trying to resolve a 403 issue. I have followed:</p>
  
  <p><a href="https://askubuntu.com/questions/365087/grant-a-user-permissions-on-www-data-owned-var-www">These steps</a> (create new group, add ubuntu and www-data to it, set group and owner to read, write and execute) </p>
  
  <p><a href="https://vijayasankarn.wordpress.com/2017/02/04/securely-setting-file-permissions-for-laravel-framework/" rel="nofollow noreferrer">These steps</a> to set folder permissions</p>
  
  <p>... many other attempts / server rebuilds...</p>
  
  <p>So just now I set all files and folders in root to 777 to test</p>
  
  <pre><code>$ find /home/ubuntu/projectname -type f -exec chmod 777 {} \;
  $ find /home/ubuntu/projectname -type d -exec chmod 777 {} \;
  </code></pre>
  
  <p>And on suggestion below I also did this:</p>
  
  <pre><code>$ namei -l /home/ubuntu/projectname/public
  f: /home/ubuntu/projectname/public
  drwxr-xr-x root     root     /
  drwxr-xr-x root     root     home
  drwxr-xr-x ubuntu   ubuntu   ubuntu
  drwxrwxrwx www-data www-data projectname
  drwxrwxrwx www-data www-data public
  
  $ sudo chmod -R 777 /home/ubuntu/projectname
  
  $ ls -l
  drwxrwxrwx   8 www-data www-data   4096 Aug 16 10:25 app
  -rwxrwxrwx   1 www-data www-data   1686 Aug 16 10:25 artisan
  drwxrwxrwx   3 www-data www-data   4096 Aug 16 10:25 bootstrap
  -rwxrwxrwx   1 www-data www-data   1652 Aug 16 10:25 composer.json
  -rwxrwxrwx   1 www-data www-data 166078 Aug 16 10:25 composer.lock
  drwxrwxrwx   2 www-data www-data   4096 Aug 16 10:25 config
  drwxrwxrwx   5 www-data www-data   4096 Aug 16 10:25 database
  drwxrwxrwx 999 www-data www-data  36864 Aug 16 10:46 node_modules
  -rwxrwxrwx   1 www-data www-data   1442 Aug 16 10:25 package.json
  -rwxrwxrwx   1 www-data www-data 604905 Aug 16 10:45 package-lock.json
  -rwxrwxrwx   1 www-data www-data   1134 Aug 16 10:25 phpunit.xml
  drwxrwxrwx   6 www-data www-data   4096 Aug 16 10:46 public
  -rwxrwxrwx   1 www-data www-data   3675 Aug 16 10:25 readme.md
  drwxrwxrwx   6 www-data www-data   4096 Aug 16 10:25 resources
  drwxrwxrwx   2 www-data www-data   4096 Aug 16 10:25 routes
  -rwxrwxrwx   1 www-data www-data    563 Aug 16 10:25 server.php
  drwxrwxrwx   6 www-data www-data   4096 Aug 16 10:25 storage
  drwxrwxrwx   4 www-data www-data   4096 Aug 16 10:25 tests
  drwxrwxrwx  45 www-data www-data   4096 Aug 16 10:45 vendor
  -rwxrwxrwx   1 www-data www-data   1738 Aug 16 10:25 webpack.mix.js
  </code></pre>
  
  <p>This last one has me stumped as the result is the same in my nginx project error log (tail -f):</p>
  
  <pre><code>2018/08/16 13:44:25 [error] 27246#27246: *1 directory index of "/home/ubuntu/projectname/public/" is forbidden, client: 29.99.0.232, server: projectname.com.au, request: "GET / HTTP/1.1", host: "projectname.com.au"
  </code></pre>
  
  <p>I do not know what to try next. <strong>Any help will get you on my Christmas card list!</strong> </p>
  
  <p>My project is cloned to:</p>
  
  <pre><code>/home/ubuntu/projectname
  </code></pre>
  
  <p>My nginx config (taken from <a href="https://laravel.com/docs/5.6/deployment" rel="nofollow noreferrer">Laravel's Deploy page</a>) is:</p>
  
  <pre><code>server {
      listen 80;
  
      server_name projectname.com.au www.projectname.com.au;
      root /home/ubuntu/projectname/public;
  
      add_header X-Frame-Options "SAMEORIGIN";
      add_header X-XSS-Protection "1; mode=block";
      add_header X-Content-Type-Options "nosniff";
  
      index index.html index.htm index.php;
  
      charset utf-8;
  
      location / {
          try_files $uri $uri/ /index.php?$query_string;
      }
  
      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;
  
      access_log  /var/log/nginx/projectname.access.log;
      error_log  /var/log/nginx/projectname.error.log error;
  
      location ~ \.php$ {
          fastcgi_split_path_info ^(.+\.php)(/.+)$;
          fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
          fastcgi_index index.php;
          include fastcgi_params;
      }
  
      location ~ /\.(?!well-known).* {
          deny all;
      }
  
      listen 443 ssl; # managed by Certbot
      ssl_certificate /etc/letsencrypt/live/projectname.com.au/fullchain.pem; # managed by Certbot
      ssl_certificate_key /etc/letsencrypt/live/projectname.com.au/privkey.pem; # managed by Certbot
      include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
      ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
  
  
  }
  
  server {
      if ($host = www.projectname.com.au) {
          return 301 https://$host$request_uri;
      } # managed by Certbot
  
  
      if ($host = projectname.com.au) {
          return 301 https://$host$request_uri;
      } # managed by Certbot
  
  
          listen 80;
          server_name projectname.com.au www.projectname.com.au;
      return 404; # managed by Certbot
  }
  </code></pre>