Issue & Question
Ubuntu Server 18.04 LTS.
Using systemctl restart on PHP-FPM doesn't create the required socket in /var/run/php/, but a reboot does.
How can I tweak my setup to allow a service restart without a reboot?
Overview
I'm compiling multiple PHP-FPM instances from source on a single server (no containers) for use with web apps of various ages. I have successfully set up PHP 7.1, PHP 7.2 and PHP 7.3 alongside one another. They all start correctly at boot, they all have a socket in /var/run/php/, they all respond as expected from a browser.
Contents of /var/run/php after boot
/var/run/php$ ls -l
total 0
srw-rw---- 1 www-data www-data 0 Apr 2 12:57 php7.1-fpm.sock
srw-rw---- 1 www-data www-data 0 Apr 2 12:57 php7.2-fpm.sock
srw-rw---- 1 www-data www-data 0 Apr 2 12:57 php7.3-fpm.sock
Each service appears to be running without issue. Here's the systemctl status output for each:
PHP 7.1 after boot
~$ sudo systemctl status php7.1-fpm
● php7.1-fpm.service - The PHP FastCGI Process Manager
Loaded: loaded (/etc/systemd/system/php7.1-fpm.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2019-04-02 12:57:51 UTC; 21min ago
Main PID: 875 (php-fpm)
Tasks: 3 (limit: 1152)
CGroup: /system.slice/php7.1-fpm.service
├─875 php-fpm: master process (/etc/php/7.1/etc/php-fpm.conf)
├─970 php-fpm: pool www
└─971 php-fpm: pool www
Apr 02 12:57:51 darwin systemd[1]: Started The PHP FastCGI Process Manager.
PHP 7.2 after boot
~$ sudo systemctl status php7.2-fpm
● php7.2-fpm.service - The PHP FastCGI Process Manager (7.2)
Loaded: loaded (/etc/systemd/system/php7.2-fpm.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2019-04-02 12:57:51 UTC; 22min ago
Main PID: 837 (php-fpm)
Tasks: 3 (limit: 1152)
CGroup: /system.slice/php7.2-fpm.service
├─837 php-fpm: master process (/etc/php/7.2/etc/php-fpm.conf)
├─963 php-fpm: pool www
└─964 php-fpm: pool www
Apr 02 12:57:51 darwin systemd[1]: Started The PHP FastCGI Process Manager (7.2).
PHP 7.3 after boot
~$ sudo systemctl status php7.3-fpm
● php7.3-fpm.service - The PHP FastCGI Process Manager (7.3)
Loaded: loaded (/etc/systemd/system/php7.3-fpm.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2019-04-02 12:57:51 UTC; 23min ago
Main PID: 836 (php-fpm)
Tasks: 3 (limit: 1152)
CGroup: /system.slice/php7.3-fpm.service
├─836 php-fpm: master process (/etc/php/7.3/etc/php-fpm.conf)
├─965 php-fpm: pool www
└─966 php-fpm: pool www
Apr 02 12:57:51 darwin systemd[1]: Started The PHP FastCGI Process Manager (7.3).
If I make a change to the respective php.ini file, this warrants a restart of the service in order for changes to be processed. In my case, when I restart the service using systemctl restart (e.g sudo systemctl restart php7.1-fpm), the service appears to restart gracefully but all the PHP sockets are deleted -- regardless of the version I restart.
There's no console output after the systemctl restart, and when I check systemctl status on the restarted service (e.g PHP 7.1 in previous paragraph), the service is running:
PHP 7.1 after systemctl restart
~$ sudo systemctl status php7.1-fpm
● php7.1-fpm.service - The PHP FastCGI Process Manager
Loaded: loaded (/etc/systemd/system/php7.1-fpm.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2019-04-02 13:28:06 UTC; 28s ago
Main PID: 1704 (php-fpm)
Tasks: 3 (limit: 1152)
CGroup: /system.slice/php7.1-fpm.service
├─1704 php-fpm: master process (/etc/php/7.1/etc/php-fpm.conf)
├─1718 php-fpm: pool www
└─1722 php-fpm: pool www
Apr 02 13:28:06 darwin systemd[1]: Stopped The PHP FastCGI Process Manager.
Apr 02 13:28:06 darwin systemd[1]: Started The PHP FastCGI Process Manager.
Note the timestamp difference on Active. If I query the other services in the same fashion (note: they have not been restarted by me), the timestamps are from the initial start at boot:
PHP 7.2 after systemctl restart on PHP 7.1
~$ sudo systemctl status php7.2-fpm
● php7.2-fpm.service - The PHP FastCGI Process Manager (7.2)
Loaded: loaded (/etc/systemd/system/php7.2-fpm.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2019-04-02 12:57:51 UTC; 33min ago
Main PID: 837 (php-fpm)
Tasks: 3 (limit: 1152)
CGroup: /system.slice/php7.2-fpm.service
├─837 php-fpm: master process (/etc/php/7.2/etc/php-fpm.conf)
├─963 php-fpm: pool www
└─964 php-fpm: pool www
Apr 02 12:57:51 darwin systemd[1]: Started The PHP FastCGI Process Manager (7.2).
PHP 7.3 after systemctl restart on PHP 7.1
~$ sudo systemctl status php7.3-fpm
● php7.3-fpm.service - The PHP FastCGI Process Manager (7.3)
Loaded: loaded (/etc/systemd/system/php7.3-fpm.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2019-04-02 12:57:51 UTC; 34min ago
Main PID: 836 (php-fpm)
Tasks: 3 (limit: 1152)
CGroup: /system.slice/php7.3-fpm.service
├─836 php-fpm: master process (/etc/php/7.3/etc/php-fpm.conf)
├─965 php-fpm: pool www
└─966 php-fpm: pool www
Apr 02 12:57:51 darwin systemd[1]: Started The PHP FastCGI Process Manager (7.3).
…and yet all the sockets are missing:
Contents of /var/run/php after systemctl restart on PHP 7.1
$ ls -l
total 0
My gut feeling is that I've mangled something in the .service file without realising. While I've been troubleshooting, I've noticed I'm using different directories for the PID and socket. The PID is not created at boot time as /run/php-fpm/ does not exist. I have a vague memory of being advised to not keep sockets and PIDs in the same directory, but I can't recall the exact details.
PHP 7.1 .service file
[Unit]
Description=The PHP FastCGI Process Manager
After=network.target
[Service]
Type=simple
RuntimeDirectory=php
RuntimePermissions=755
PIDFile=/run/php-fpm/php7.1-fpm.pid
ExecStart=/etc/php/7.1/sbin/php-fpm --nodaemonize --fpm-config /etc/php/7.1/etc/php-fpm.conf
ExecReload=/bin/kill -USR2 $MAINPID
[Install]
WantedBy=multi-user.target
Thank you in advance for any pointers or further reading.