Linux PHP Servers Useful

PHP-FPM Service – How to start,stop,reload – Ubuntu Linux Severs

Used with many web servers like Apache, Nginx, and other, PHP-FPM is a FastCGI process manager for PHP.

Sometimes we need to restart the server for various reasons: changing settings for example, and depending on what linux we have on the server there are some variations in the commands used.

Ubuntu/Debian Linux (Ubuntu Linux 16.04+; 18.04; 20.02 LTS or Debian Linux 8.x+)

@ sudo systemctl start php7.4-fpm.service # start php-fpm
@ sudo systemctl stop php7.4-fpm.service # stop php-fpm
@ sudo systemctl restart php7.4-fpm.service # restart php-fpm
@ sudo systemctl reload php7.4-fpm.service # reload php-fpm


@ sudo service php7.4-fpm start # start php-fpm
@ sudo service php7.4-fpm stop # stop php-fpm
@ sudo service php7.4-fpm restart # restart php-fpm
@ sudo service php7.4-fpm reload # reload php-fpm

The examples are for php-fpm version 7.4, but for other versions you have to change the command to correspond to the installed / active version.

To find out the php version, use the following command:

php -version
PHP 7.4.13 (cli) (built: Nov 28 2020 06:24:59) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.13, Copyright (c), by Zend Technologies

Or if you prefer the shorter version, the result of command is similar:

@ php -v

So the release php version is PHP 7.4.13 and the minor php version is 7.4 !

Bonus: universal solution

A universal solution without knowing beforehand the php version, is to use the following command form:

@ sudo service php$(php -r 'echo PHP_MAJOR_VERSION.".".PHP_MINOR_VERSION;')-fpm status
● php7.4-fpm.service - The PHP 7.4 FastCGI Process Manager
     Loaded: loaded (/lib/systemd/system/php7.4-fpm.service; enabled; vendor preset: enabled)
     Active: active (running) since Sat 2020-12-26 19:05:18 UTC; 5s ago
       Docs: man:php-fpm7.4(8)
    Process: 1630 ExecStartPost=/usr/lib/php/php-fpm-socket-helper install /run/php/php-fpm.sock /etc/php/7.4/fpm/pool.d/www.conf 74 (code=exited, st>
   Main PID: 1627 (php-fpm7.4)
     Status: "Ready to handle connections"
      Tasks: 1 (limit: 614)
     Memory: 51.1M
     CGroup: /system.slice/php7.4-fpm.service
             └─1627 php-fpm: master process (/etc/php/7.4/fpm/php-fpm.conf)

Dec 26 19:05:18 systemd[1]: Starting The PHP 7.4 FastCGI Process Manager...
Dec 26 19:05:18 systemd[1]: Started The PHP 7.4 FastCGI Process Manager.

Leave a Reply

Your email address will not be published. Required fields are marked *