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 
OR
$ 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
OR
$ 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
OR
$ 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 127.0.0.1 for security reasons.

location ~ ^/(status|ping)$ {
        allow 127.0.0.1;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_index index.php;
        include fastcgi_params;
        #fastcgi_pass 127.0.0.1:9000;
        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:

http://www.foo.bar/status?full

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

http://www.foo.bar/status?json&full
http://www.foo.bar/status?html&full
http://www.foo.bar/status?xml&full

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.

Hey TecMint readers,

Exciting news! Every month, our top blog commenters will have the chance to win fantastic rewards, like free Linux eBooks such as RHCE, RHCSA, LFCS, Learn Linux, and Awk, each worth $20!

Learn more about the contest and stand a chance to win by sharing your thoughts below!

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.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

2 Comments

Leave a Reply
  1. You can just use this ‘PHP-FPM real-time status page’ script without any configuration:

    https://gist.github.com/EhsanCh/97187902e905a308ce434bda6730073c

    Reply
  2. I’m getting a blank page.

    on access.log it is ok.

    on error.log nothing is recorded.

    default:
    location = /php-fpm-status {
    #     access_log off;
         allow 127.0.0.1;
    #     deny all;
         include fastcgi_params;
    #     fastcgi_pass 127.0.0.1:9000;
          fastcgi_pass unix:/run/php/php7.0-fpm.sock;
     }
    

    When I insert these two lines:

    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_index index.php;
    

    I start to get an error on error.log:

    2020/07/23 21:50:24 [error] 11585#11585: *71685 FastCGI sent in stderr: "Access to the script '/usr/share/nginx/html/php-fpm-status' has been denied (see security.limit_extensions)" while reading response header from upstream, client: 127.0.0.1, server: _, request: "GET /php-fpm-status HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.0-fpm.sock:", host: "127.0.0.1"
    

    security.limit_extensions is default to .php.

    Any ideas?

    Reply

Got Something to Say? Join the Discussion...

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.