502 Bad Gateway-Linux, php7, nginx. How to solve this error?
I am having an Error 502 that represents some configuration on the server, when I try to open a website using linux, nginx and php7. Searching for some other POSTS, Link about the same error I see that php needs the fpm to be recognized in nginx. But the fpm is installed and updated. See photo below:
According to the error 505 there's something going on on the server. It should not be php-7 (I think). Does anyone have any idea of what could be?
Updating
And finally it seems that it is an error due to PHP. I tested with an html file and had no problems. So it looks like it has something with php itself. What can it be?
Last logs
2016/07/06 06:14:56 [crit] 834#834: *15 connect() to unix:/var/run/php5-fpm.sock failed (2: No such file or directory) while connecting to upstream, client: 127.0.0.1, server: ig.app, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "ig.app"
2016/07/06 06:15:04 [crit] 834#834: *15 connect() to unix:/var/run/php5-fpm.sock failed (2: No such file or directory) while connecting to upstream, client: 127.0.0.1, server: ig.app, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "ig.app"
2016/07/06 06:15:04 [crit] 834#834: *15 connect() to unix:/var/run/php5-fpm.sock failed (2: No such file or directory) while connecting to upstream, client: 127.0.0.1, server: ig.app, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "ig.app"
2016/07/06 06:16:29 [crit] 834#834: *15 connect() to unix:/var/run/php5-fpm.sock failed (2: No such file or directory) while connecting to upstream, client: 127.0.0.1, server: ig.app, request: "GET /index.php HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "ig.app"
1 answers
The Solution
Updating Nginx Site (s) to use new socket Path
Nginx communicates with PHP-FPM using a Unix domain socket . Sockets map to a path in the air system.
ancient
PHP 5 / var / run / php5-fpm.sock
That is.. It looked like this:
fastcgi_pass unix:/var/run/php/php5-fpm.sock;
new configuration
PHP 7
/var/run/php/php7.0-fpm.sock
And it looks like this:
fastcgi_pass unix:/var/run/php/php7.0-fpm.sockk;
The site configuration can be found in different folders depending on the system you use. Then search in case you don't find it. In this answer we will use one of the standard paths.
Editing the NGNIX Ste configuration file
> sudo nano /etc/nginx/sites-available/default
server {
listen 80;
root /usr/share/nginx/www;
index index.php index.html index.htm;
server_name example.com;
location / {
try_files $uri $uri/ /index.html;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/www;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sockk;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
SOCKET settings may vary due to NGINX version as well as operating system version. The PHP version can also interfere. In case your server has no reference in standard files. Always search by quoting the system operating. Note that the" version " of the Socket is always changed, along with the PHP-FPM version. But not necessarily the number as in the example must be present.