How to Daemonize PHP-FPM Using systemd and Supervisor
This article explains common reasons why PHP-FPM processes may terminate unexpectedly and provides step‑by‑step instructions for configuring systemd and Supervisor to supervise PHP‑FPM, ensuring continuous and reliable operation on Linux servers.
PHP-FPM is a FastCGI process manager for PHP scripts that works with Nginx, Apache, or other FastCGI‑compatible web servers, and ensuring its stability often requires process supervision.
Common problems : crashes, resource exhaustion, and unexpected exits can cause the PHP‑FPM service to stop.
Using systemd : edit the service file, add unit and service sections, then start and enable the service.
$ sudo vi /etc/systemd/system/php-fpm.service
[Unit]
Description=PHP FastCGI Process Manager
After=network.target
[Service]
ExecStart=/usr/local/php/sbin/php-fpm --nodaemonize --fpm-config /usr/local/php/etc/php-fpm.conf
[Install]
WantedBy=multi-user.targetStart and enable the service:
$ sudo systemctl start php-fpm
$ sudo systemctl enable php-fpmUsing Supervisor : install Supervisor, create a program configuration, then start Supervisor and the PHP‑FPM program.
$ sudo apt-get install supervisor
$ sudo vi /etc/supervisor/conf.d/php-fpm.conf
[program:php-fpm]
command=/usr/local/php/sbin/php-fpm --nodaemonize --fpm-config /usr/local/php/etc/php-fpm.conf
autostart=true
autorestart=true
startretries=3
user=nobody
redirect_stderr=true $ sudo systemctl start supervisor
$ sudo supervisorctl start php-fpmBoth systemd and Supervisor will automatically restart PHP‑FPM if it exits unexpectedly, improving reliability.
Choose the method that fits your environment to keep PHP‑FPM running smoothly.
php中文网 Courses
php中文网's platform for the latest courses and technical articles, helping PHP learners advance quickly.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.