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

前端 未结 8 1747
走了就别回头了
走了就别回头了 2021-02-07 01:05

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

相关标签:
8条回答
  • 2021-02-07 01:47

    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

    0 讨论(0)
  • 2021-02-07 01:49

    first, as the log, your problem is...

    you dont have the sock! the sock (php7.2-fpm----) is made when you start php.

    1. check the location to make the sock.

      • go to /etc/php/7.2/fpm/pool.d/ -> www.conf
      • you can see the listen = "something something" <-- this is the location address.
      • if it is not /var/run/php/php7.2-fpm.sock, replace it.
    2. run php (sudo service php7.2-fpm restart)

    3. check the folder you download sock (var/run/php)
    4. if you get the sock, restart your nginx
    5. if you get error, that means your nginx setting (to find the sock) is wrong.
    6. go to etc -> nginx -> sites-enabled and open default
    7. if fastcgi_pass unix:/run/php/php7.2-fpm.sock; is not, replace them.
    8. save and run it.

    finish.

    0 讨论(0)
  • 2021-02-07 01:52

    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

    0 讨论(0)
  • 2021-02-07 01:54

    Mine was inside another php folder, so:
    /var/run/php/php7.2-fpm.sock

    • Ubuntu 18.04
    • Php 7.2
    0 讨论(0)
  • 2021-02-07 01:56

    /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

    0 讨论(0)
  • 2021-02-07 02:03

    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
    
    0 讨论(0)
提交回复
热议问题