Nginx – PHP-FPM not working on sockets but TCP only

debiannginxphp-fpmsocket

I have PHP5-FPM installed on Debian with nginx. When I try to open a PHP page then I get Error 502 Bag Gateway. I found out that it is because I am using sockets which looks like is not properly configured. I have tried to fix it by applying different settings but unable to solve this issue. If I change sockets to 127.0.0.1:9000 then it works fine.

Can you please check following configuration and tell me what am I doing wrong?

pool.d/sf.conf

user = sf
group = sf
listen = /var/run/php5-fpm-sf.sock
listen.owner = sf
listen.group = sf
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
chdir =/

In above file I am using /var/run/php5-fpm-sf.sock because /var/run/php5-fpm.sock is already being used by pool.d/www.conf

php5-fpm-sf.sock permission

srw-rw-rw- 1 sf sf 0 Aug 10 12:21 /var/run/php5-fpm-sf.sock

sites-available/sf

fastcgi_pass unix:/var/run/php5-fpm-sf.sock

/var/log/nginx/error.log

2017/08/10 12:37:37 [crit] 11666#0: *3 connect() to
unix:/var/run/php5-fpm-sf.sock failed (13: Permission denied) while
connecting to upstream, client: 162.125.12.13, server: www.sf.com,
request: "GET /phptest.php HTTP/1.1", upstream:
"fastcgi://unix:/var/run/php5-fpm-sf.sock:", host: "sf.com"

Best Answer

You just need to change listen.owner and listen.group to www-data in your pool conf file

user = sf
group = sf
listen = /var/run/php5-fpm-sf.sock
listen.owner = www-data
listen.group = www-data

And don't forget to restart fpm and nginx service