Restart a php8.1-fpm.service automatically after stopped on Nginx Ubuntu Server

In order to restart php8.1-fpm automatically after stopped on Nginx Ubuntu Server, you may add the following:

1. Edit php8.1-fpm.service using nano command or open file via ftp client

$ nano /lib/systemd/system/php8.1-fpm.service

2. Add the following 2 lines at the bottom of [Service]:

[Service]

Restart=on-failure

RestartSec=5s

3. Restart the servie with systemctl cmd:

$ sudo systemctl daemon-reload

4. Check php8.1-fpm.service status

$ sudo systemctl status php8.1-fpm.service

5. Restart the service to verify again

sudo systemctl status php8.1-fpm.service

then

check the status to confirm

$ sudo systemctl status php8.1-fpm.service


Now, the PHP service will restart automatically whenever stopped but I would advise to check the php8.1-fpm log ocassionally to make sure it's not failing often and the reason of stopping.

Your link is almost ready.

12
Seconds
Please wait...