title: Laravel on Nginx: accessing to "public/" of the app results in "Permission denied" even though it has the same user as Nginx
body: <p>I've been trying to deploy a brand new Laravel 6 app on Nginx with CentOS 7, but I'm getting the following error messages on the error log.</p>
  
  <pre><code>*13 stat() "/ROOT_OF_APP/public/" failed (13: Permission denied), 
  client: 127.0.0.1, server: HOST_NAME, request: "GET / HTTP/1.1", host: "HOST_NAME"
  
  *13 stat() "/ROOT_OF_APP/public/" failed (13: Permission denied), 
  client: 127.0.0.1, server: HOST_NAME, request: "GET / HTTP/1.1", host: "HOST_NAME"
  
  *13 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, 
  client: 127.0.0.1, server: HOST_NAME, request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "HOST_NAME"
  
  </code></pre>
  
  <p>The first line says <code>"/ROOT_OF_APP/public/" failed (13: Permission denied)</code>.</p>
  
  <p>So, I ran <code>sudo chown -R nignx:nginx /ROOT_OF_APP/public/</code> and <code>sudo chmod -R 775 /ROOT_OF_APP/</code>, and made sure that the user and group of both Nginx and PHP-FPM are <code>nginx</code> (this will be explained below).</p>
  
  <p>The question is:
  <strong><em>why can't nginx access "public" even though the owner/user is nginx ?</em></strong></p>
  
  <p>(The 3rd message (<code>Primary script unknown</code>) also bothers me, but I don't know if this is to do with the permission issue)</p>
  
  <p>In <code>/etc/php-fpm.d/www.conf</code>, you see these lines.</p>
  
  <pre><code>user = nginx
  group = nginx
  
  listen.owner = nginx
  listen.group = nginx
  listen.mode = 0660
  </code></pre>
  
  <p>In <code>/etc/nginx/nginx.conf</code>, you see the line.</p>
  
  <pre><code>user nginx;
  </code></pre>
  
  <p>(I'd like to note that the OS is <strong>CentOS 7</strong>, so it doesn't have <code>www-data</code> user/group, unlike <strong>Ubuntu</strong>.)</p>
  
  <p>If I run <code>ps aux | grep php-fpm</code>...</p>
  
  <pre><code>user     24394  0.0  0.0 112708   988 pts/1    S+   14:28   0:00 grep --color=auto php-fpm
  root     26979  0.0  0.0 306464 10520 ?        Ss   13:57   0:00 php-fpm: master process (/etc/php-fpm.conf)
  nginx    26985  0.0  0.0 318712  5804 ?        S    13:57   0:00 php-fpm: pool www
  nginx    26986  0.0  0.0 318712  5796 ?        S    13:57   0:00 php-fpm: pool www
  nginx    26987  0.0  0.0 318712  5800 ?        S    13:57   0:00 php-fpm: pool www
  nginx    26988  0.0  0.0 318712  5800 ?        S    13:57   0:00 php-fpm: pool www
  nginx    26989  0.0  0.0 318712  5804 ?        S    13:57   0:00 php-fpm: pool www
  </code></pre>
  
  <p>If I ran <code>ps aux | grep nginx</code>...</p>
  
  <pre><code>root      2990  0.0  0.0 122420  5608 ?        Ss   14:01   0:00 nginx: master process /usr/sbin/nginx
  nginx    26985  0.0  0.0 318712  5804 ?        S    13:57   0:00 php-fpm: pool www
  ...
  # The 2nd line is repeated several times
  ...
  nginx    31299  0.0  0.0 134672  4212 ?        S    14:15   0:00 nginx: worker process
  # This "nginx: worker process" is repeated several times too
  </code></pre>
  
  <p>I'm completely clueless... any advice will be appreciated.</p>
  
  <p><strong><em>PS</em></strong></p>
  
  <p>Here's how the config file looks like.</p>
  
  <pre><code>server {
          listen 80;
          listen [::]:80 ipv6only=on;
  
          access_log /var/log/nginx/MY-APP-access.log;
          error_log /var/log/nginx/MY-APP-error.log;
  
          root /ROOT_OF_APP/public;
          index index.php index.html index.htm;
  
          server_name HOST_NAME;
  
            location / {
              try_files $uri $uri/ /index.php?$args;
            }
  
            location ~* \.php$ {
                include /etc/nginx/fastcgi_params;
                fastcgi_pass 127.0.0.1:9000;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                fastcgi_index index.php;
          }
  
          location = /favicon.ico { log_not_found off; access_log off; }
            location = /robots.txt  { log_not_found off; access_log off; }
  }
  </code></pre>
  
  <p><code>sudo nginx -t</code> shows that the syntax is ok.</p>
  
  <p>Also, the <code>"SELinux enforcing"</code> status has been changed into "Permissive", so SELinux shouldn't be the cause of this issue.</p>