Solved: connect() to unix:/run/php/php7.1-fpm.sock failed (13: Permission denied) while connecting to upstream

When I was trying to open php file from browser url, I was getting error. I checked error log with this command: tail -f /opt/nginx/logs/error.log and I found this message in error log:
connect() to unix:/run/php/php7.1-fpm.sock failed (13: Permission denied) while connecting to upstream

It looks like, it is user permission related issue.

I check nginx process with this command: ps aux | grep nginx

root      3934  0.0  0.2  43416  1488 ?        Ss   13:11   0:00 nginx: master process /opt/nginx/sbin/nginx
deployer  3937  0.0  0.7  43632  3920 ?        S    13:11   0:00 nginx: worker process
deployer  4304  0.0  0.1  14516   952 pts/0    S+   13:17   0:00 grep --color=auto nginx

I checked /run/php/php7.1-fpm.sock file permission with this command: ls -l /run/php/php7.1-fpm.sock

srw-rw---- 1 www-data www-data 0 Sep 3 09:52 /run/php/php7.1-fpm.sock


Now it is clear that, nginx server is running with deployer user and /run/php/php7.1-fpm.sock file owner is www-data.
So. I changed nginx user to www-data. ( I added user www-data; to nginx configuration file)
sudo vim /opt/nginx/conf/nginx.conf

user www-data;
worker_processes  1;
http {
    ..... other configuration
}

Now check nginx configuration with this command: sudo /opt/nginx/sbin/nginx -t

nginx: the configuration file /opt/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /opt/nginx/conf/nginx.conf test is successful

Kill all nginx process with this command: sudo kill -9 $(ps aux | grep nginx | awk '{print $2}')


Again, check nginx process with this command: ps aux | grep nginx

deployer  4306  0.0  0.1  14516   952 pts/0    S+   13:17   0:00 grep --color=auto nginx

You are seeing 1 process, that means nginx is not running.


start nginx server with this command: sudo /opt/nginx/sbin/nginx

Topic: