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.
*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"
The first line says "/ROOT_OF_APP/public/" failed (13: Permission denied)
.
So, I ran sudo chown -R nignx:nginx /ROOT_OF_APP/public/
and sudo chmod -R 775 /ROOT_OF_APP/
, and made sure that the user and group of both Nginx and PHP-FPM are nginx
(this will be explained below).
The question is:
why can’t nginx access “public” even though the owner/user is nginx ?
(The 3rd message (Primary script unknown
) also bothers me, but I don’t know if this is to do with the permission issue)
In /etc/php-fpm.d/www.conf
, you see these lines.
user = nginx
group = nginx
listen.owner = nginx
listen.group = nginx
listen.mode = 0660
In /etc/nginx/nginx.conf
, you see the line.
user nginx;
(I’d like to note that the OS is CentOS 7, so it doesn’t have www-data
user/group, unlike Ubuntu.)
If I run ps aux | grep php-fpm
…
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
If I ran ps aux | grep nginx
…
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
I’m completely clueless… any advice will be appreciated.
PS
Here’s how the config file looks like.
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; }
}
sudo nginx -t
shows that the syntax is ok.
Also, the "SELinux enforcing"
status has been changed into “Permissive”, so SELinux shouldn’t be the cause of this issue.
2
Answers
This happens to me when I tried putting my project outside /var/www>
I would suggest to put your project in /var/www/project_folder
then change your nginx configuration file as required then.
It will work.
This sounds like it could be an SELinux issue, especially as others have pointed out, since you are in the non-default directory.
Is SELinux enforcing? (run “getenforce”)
If that comes back “Enforcing” I’d bet that’s the issue.
If so, you can disable it temporarily, restart your services, see if the issue goes away (run “setenforce 0”)
Then, assuming you want SELinux on, (highly recommended to say the least) investigate the output of “ausearch -m AVC”. Post back here for help.