502 Bad Gateway nginx php7 fpm

Solution 1:

Try to check your nginx's www.conf file and make sure the socket path is correct and socket file is present at that location while these services are running.

ie, /var/run/php/php7.0-fpm.sock or

/dev/shm/php-fpm-www.sock

try to start php-fpm from init.d

/etc/init.d/php-7.0.0-fpm start

and check your php.ini file also

add the following to the end of the file

[apc]
apc.write_lock = 1
apc.slam_defense = 0

Solution 2:

It is likely that an older libpcre3 is installed and satisfies the dependency in the php7.0 package, but only the newer library package provides pcre_jit_stack_free.

If this is the case, do an apt-get install libpcre3, and you’re good to go.

Ref.: https://github.com/oerdnj/deb.sury.org/issues/372

Solution 3:

I'd literally been fighting this for days, when I found the solution. It was a typo in /etc/nginx/sites-available/www (copied originally from ...sites-available/default and modified).

I'd overlooked this in both the file itself and the /var/log/nginx/error.log --even though the error log was clear

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

The connection line should have read unix: /var/run/php/php7.0-fpm.sock.

Duh.