How to Enable and Monitor PHP-FPM Status in Nginx

PHP-FPM (FastCGI Process Manager) is an alternative PHP FastCGI implementation that comes with a number of extra features useful for websites of any size, particularly sites that receive high traffic.

It is commonly used in the LEMP (Linux Nginx MySQL/MariaDB PHP) stack; Nginx uses PHP FastCGI for serving dynamic HTTP content on a network. It is being used to serve millions of PHP requests for hundreds of websites on web servers on the internet.

Read Also: How to Enable NGINX Status Page

One of the useful features of php-fpm is the built-in status page, which can help you monitor its health. In this article, we will show how to enable the PHP-FPM status page on Linux.

How to Enable PHP-FPM Status Page in Linux

First open the php-fpm configuration file and enable the status page as shown.

$ sudo vim /etc/php-fpm.d/www.conf 
$ sudo vim /etc/php/7.2/fpm/pool.d/www.conf	#for PHP versions 5.6, 7.0, 7.1

Inside this file, find and uncomment the variable pm.status_path = /status as shown in the screenshot.

Enable PHP-FPM Status Page

Enable PHP-FPM Status Page

Save the changes and exit the file.

Next, check that the PHP-FPM configuration file for any errors by running the command below.

$ sudo php-fpm -t
$ sudo php7.2-fpm -t
Check PHP-FPM Configuration File

Check PHP-FPM Configuration File

Then restart the PHP-FPM service to apply the recent changes.

$ sudo systemctl restart php-fpm
$ sudo systemctl restart php7.2-fpm

Next, edit your default server block (virtual host) configuration file and add the location block below in it. For instance on the test system, the default server block’s config file is /etc/nginx/conf.d/default.conf, for the site test.lab.

$ sudo vim /etc/nginx/conf.d/default.conf 

Here is the location block to be added. In this config, we have only allowed access to PHP-FPM process status within the localhost using the directive allow for security reasons.

location ~ ^/(status|ping)$ {
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_pass   unix:/var/run/php7.2-fpm.sock;

Save the file and close it.

Then restart the Nginx server to apply the above changes.

$ sudo systemctl restart nginx

Now open a browser and type the URL http://test.lab/status to view your PHP-FPM process status.

View PHP-FPM Status Page

View PHP-FPM Status Page

Alternatively, use the curl program as follows, where the -L flag specifies the location of the page.

$ curl -L http://test.lab/status

By default, the status page only prints out a summary or short status. To view status for each pool process, pass “full” in the query string, for instance:

You can define the output format (JSON, HTML or XML) as shown.

Below are the values returned in the php-fpm full status, for each process:

  • pid – PID of the process.
  • state process status (idle, running, etc.).
  • start time – date and time the process has started.
  • start since – number of seconds since the process has started.
  • requests – number of requests the process has served.
  • request duration – duration in µs of the requests.
  • request method – request method (GET, POST, etc.).
  • request URI – request URI with the query string.
  • content length – content length of the request (only with POST).
  • user – user (PHP_AUTH_USER) (or ‘-‘ if not set).
  • script – main script called (or ‘-‘ if not set).
  • last request cpu – %cpu the last request consumed (note that it’s always 0 if the process is not in Idle state).
  • last request memory – max amount of memory the last request consumed (it’s always 0 if the process is not in Idle state).

That’s it for now! In this article, we have explained how to enable the php-fpm status page under Nginx web server. Use the feedback form below to share your thoughts with us.

Best Affordable Linux and WordPress Services For Your Business
Outsource Your Linux and WordPress Project and Get it Promptly Completed Remotely and Delivered Online.

If You Appreciate What We Do Here On TecMint, You Should Consider:

  1. Stay Connected to: Twitter | Facebook | Google Plus
  2. Subscribe to our email updates: Sign Up Now
  3. Get your own self-hosted blog with a Free Domain at ($3.45/month).
  4. Become a Supporter - Make a contribution via PayPal
  5. Support us by purchasing our premium books in PDF format.
  6. Support us by taking our online Linux courses

We are thankful for your never ending support.

Aaron Kili

Aaron Kili is a Linux and F.O.S.S enthusiast, an upcoming Linux SysAdmin, web developer, and currently a content creator for TecMint who loves working with computers and strongly believes in sharing knowledge.

Your name can also be listed here. Got a tip? Submit it here to become an TecMint author.

RedHat RHCE and RHCSA Certification Book
Linux Foundation LFCS and LFCE Certification Preparation Guide

You may also like...

Got something to say? Join the discussion.

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.