Can't bind php7.4-fpm listening socket because folder does not exist?

Viewed 2636

So hi.

Everytime my server reboots, my web services are unreachable because of 502 errors. It took me a long time to figure out the root of the problem, but basically what happened was that the php7.4-fpm service could not be restarted after rebooting:

timon@nur1kleinerserver:/etc/nginx$ systemctl status php7.4-fpm.service
ā— php7.4-fpm.service - The PHP 7.4 FastCGI Process Manager
   Loaded: loaded (/lib/systemd/system/php7.4-fpm.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Mon 2020-10-05 21:52:43 CEST; 19s ago
     Docs: man:php-fpm7.4(8)
  Process: 21734 ExecStopPost=/usr/lib/php/php-fpm-socket-helper remove /run/php/php-fpm.sock /etc/php/7.4/fpm/pool.d/www.conf 74 (code=exited, status=0/SUCCESS)
  Process: 21732 ExecStart=/usr/sbin/php-fpm7.4 --nodaemonize --fpm-config /etc/php/7.4/fpm/php-fpm.conf (code=exited, status=78)
 Main PID: 21732 (code=exited, status=78)

Okt 05 21:52:43 nur1kleinerserver systemd[1]: Starting The PHP 7.4 FastCGI Process Manager...
Okt 05 21:52:43 nur1kleinerserver php-fpm7.4[21732]: [05-Oct-2020 21:52:43] ERROR: unable to bind listening socket for address '/run/php/php7.4-fpm.sock': No such file or directory (2)
Okt 05 21:52:43 nur1kleinerserver php-fpm7.4[21732]: [05-Oct-2020 21:52:43] ERROR: FPM initialization failed
Okt 05 21:52:43 nur1kleinerserver systemd[1]: php7.4-fpm.service: Main process exited, code=exited, status=78/n/a
Okt 05 21:52:43 nur1kleinerserver systemd[1]: php7.4-fpm.service: Failed with result 'exit-code'.
Okt 05 21:52:43 nur1kleinerserver systemd[1]: Failed to start The PHP 7.4 FastCGI Process Manager.

And after an entire day of looking for a fix, you know what did fix it?

timon@nur1kleinerserver:/etc/nginx$ sudo mkdir -p /var/run/php/ 
timon@nur1kleinerserver:/etc/nginx$ sudo systemctl restart php7.4-fpm

I followed this suggestion by the way.

So, bottom-line question: how do I make this fix permanent? Every time the server reboots, I have to go through this again. Why does the folder disappear and how can I change that?

Edited a year later to append solution. Well, less of a solution than a workaround. I implemented a root cronjob to run at boot to execute a shell script consisting of my fix. So if you're having this problem, simply create an executable bash script by navigating to a folder of your liking and then

sudo nano test.sh

NB: not sure if creating this as root is strictly necessary, but I want to avoid the script not executing because of ownership issues.

Create the script:

#!/bin/bash
# bash script to mkdir php7.4 socket on reboot to make nginx work correctly because it doesn't automatically for whatever reason
mkdir -p /var/run/php/
systemctl restart php7.4-fpm

Save it. Make it executable by

sudo chmod +x test.sh

Set up a sudo cronjob to run at boot by adding it to sudo user's crontab:

sudo crontab -e

add a new line:

 @reboot /path/to/script/test.sh

Voila, problem "solved".

0 Answers
Related