nginx not able to connect to php-fpm socket

This is a gotcha that many tutorials omit. the php user should be the owner of the socket. So you want to make sure that

chown www-data:www-data /var/run/php5-fpm.socket

I don't know what caused this exactly, probably some changes in PHP code, but I've found a way to fix this:

1) Open your pool configuration as root, mine is in: /etc/php5/fpm/pool.d/www.conf

2) Add the following lines:

  • listen.owner = www-data
  • listen.group = www-data

Here's the complete documentation for all config parameters.

3) Restart PHP FPM: sudo service php5-fpm restart

It should re-create socket file with proper user and group:

ls -lah /var/run/ | grep php: -rw-r--r-- 1 root root 4 Jun 24 18:19 php5-fpm.pid srw-rw---- 1 www-data www-data 0 Jun 24 18:19 php5-fpm.sock

I hope it will help! Cheers!