NGINX: connect() to unix:/var/run/php7.0-fpm.sock failed (2: No such file or directory)

Question:

I’m trying to deploy a basic php application using ansible but while adjusting it for Ubuntu 16.04 with php7. Below this message you’ll find my Ansible file. After running it and trying to visit the page in the browser I get a 404, and the following in the nginx error logs:

2016/10/15 13:13:20 [crit] 28771#28771: *7 connect() to
unix:/var/run/php7.0-fpm.sock failed (2: No such file or directory)
while connecting to upstream, client: 93.xxx.xxx.xx, server:
95.xx.xx.xx, request: “GET / HTTP/1.1”, upstream: “fastcgi://unix:/var/run/php7.0-fpm.sock:”, host: “95.xx.xx.xx”

So I checked if the socket file exists, and it seems to exist, but ls behaves weird:

Why can ls find the socket file if I search it by part of the name php while it cannot find the socket file when I list more than that php7 or even the full name php7.0-fpm.sock?

And most importantly, how can I make this work with nginx? All tips are welcome!

below I pasted my Ansible file

Answer:

Had the same problem.
Solution is very easy.

In nginx conf file you are trying upstreaming to

unix:/var/run/php7.0-fpm.sock

Correct path is

unix:/var/run/php/php7.0-fpm.sock


There is a mention about this in the documentation

Nginx communicates with PHP-FPM using a Unix domain socket. Sockets
map to a path on the filesystem, and our PHP 7 installation uses a new
path by default:

PHP 5 /var/run/php5-fpm.sock

PHP 7 /var/run/php/php7.0-fpm.sock

Leave a Reply