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.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

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

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.