PHP-FPM (FastCGI Process Manager) is an alternative PHP FastCGI implementation that is known for its high performance, especially when dealing with high-traffic websites. It is a widely-used method for managing PHP processes and has powerful features, such as adaptive process management and the ability to manage multiple pools with different configurations.
However, there may be situations where you need to stop PHP-FPM, either for maintenance purposes or to troubleshoot an issue. In this blog post, we will explore different methods for stopping PHP-FPM gracefully, ensuring that your PHP processes are shut down without affecting your server’s stability or the user experience.
Method 1: Using the ‘php-fpm’ command
One of the easiest ways to stop PHP-FPM is by using the php-fpm command with the –pid option. First, you need to locate the PHP-FPM process ID (PID) file which is usually stored in the /var/run directory. The PID file is typically named php-fpm.pid or php7.4-fpm.pid (depending on your PHP version).
Once you have located the PID file, you can use the following command to stop PHP-FPM:
Replace /path/to/php-fpm.pid and /path/to/php-fpm.conf with the actual paths to your PID file and PHP-FPM configuration file, respectively.
Method 2: Using the ‘kill’ command
You can also stop PHP-FPM by sending the SIGQUIT signal to the master process using the kill command. First, you need to find the PHP-FPM master process ID by running the following command:
This command will show a list of processes that match the search string. Look for the process with the description “php-fpm: master process” and note its PID (the second column in the output).
Now, use the kill command with the -SIGQUIT option to send the signal to the master process:
Replace <master_process_PID> with the actual PID of the PHP-FPM master process.
Method 3: Using the ‘systemctl’ or ‘service’ command
If your server uses systemd (most modern Linux distributions do), you can stop PHP-FPM using the systemctl command:
For servers that use the init system, you can use the service command instead:
Keep in mind that the service name may vary depending on your PHP version, so adjust the command accordingly (e.g., php7.4-fpm).
In this blog post, we have covered three methods to stop PHP-FPM gracefully, ensuring that your PHP processes are shut down in a controlled manner. Remember to always follow best practices and perform maintenance tasks during low-traffic periods to minimize any potential impact on your server and end-users.