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 then it works fine.

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


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


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


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:, server: www.sf.com, request: "GET /phptest.php HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm-sf.sock:", host: "sf.com"

  • Have you verified 'sf' user permission on domain's root directory? Aug 10, 2017 at 18:05
  • Root directory has this permission drwxr-xr-x 2 root root 4096 Aug 10 10:48 html. Does it look ok? Aug 10, 2017 at 18:25
  • I tested by giving my testfile.php full permissions 777 but it shows same error so I guess it is not related to permission. Aug 10, 2017 at 18:40

1 Answer 1


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

  • Thanks it fixed the issue. There is small mistake in your answer i.e. it should be www-data in last line. Aug 10, 2017 at 19:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.