Backend Development 4 min read

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中文网 Courses
php中文网 Courses
php中文网 Courses
How to Daemonize PHP-FPM Using systemd and Supervisor

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.target

Start and enable the service:

$ sudo systemctl start php-fpm
$ sudo systemctl enable php-fpm

Using 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-fpm

Both 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.

backendProcess ManagementLinuxPHP-FPMSupervisorsystemd
php中文网 Courses
Written by

php中文网 Courses

php中文网's platform for the latest courses and technical articles, helping PHP learners advance quickly.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.