I\'ve just recently moved my websites from apache2 to Nginx as my new web server backend. got to love problems aha.
HTML files in the web host director work prior to php
If u are running latest PHP version
e.g `php7.4`
then sudo apt-get install php7.4-fpm
and then sudo service nginx restart
sudo service php7.4-fpm restart
. Also remember to change the name in the /etc/nginx/site-enable/example.com
as well
first, as the log, your problem is...
you dont have the sock! the sock (php7.2-fpm----) is made when you start php.
check the location to make the sock.
run php (sudo service php7.2-fpm restart)
finish.
A possible explanation, as I just faced: the disk was full.
Php-fpm was logging the error, and after a while the php-fpm cgi service did crash and wasn't able to restart, while my server (Caddy) was still online. (Had also a bunch of scripts writing to disc in the same time).
This was leading to the http error 502 Bad Gateway
.
The solution is to leave a large amount of hdd space, empty the trash, empty the apt cache, and else. Make sure to find the cause of the problem, so the issue doesn't come back. Watch your logs time to time.
Then, on my machine (use your php-fpm version):
/etc/init.d/php7.2-fpm restart
Alternatives way to restart
Mine was inside another php
folder, so:
/var/run/php/php7.2-fpm.sock
/var/run/
is probably actually a symlink to /run/
/run/
belongs to root and permissions are 755. php-fpm is running as www-data so can't create a socket in /run/
The solution is to create /run/php/
and change ownership to www-data, then change your socket path to /run/php/php-fpm.socket
Reinstall php-fpm works for me:
apt-get purge php7.3-fpm
rm -rf /etc/php/7.3/fpm/
apt-get install php7.3-fpm
service nginx restart
service php7.3-fpm restart