1

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"

  • Have you verified 'sf' user permission on domain's root directory? – Mukesh Jagani Aug 10 '17 at 18:05
  • Root directory has this permission drwxr-xr-x 2 root root 4096 Aug 10 10:48 html. Does it look ok? – Frank Martin Aug 10 '17 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. – Frank Martin Aug 10 '17 at 18:40
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. – Frank Martin Aug 10 '17 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.