Topics

On this page

Last updated on Dec 18, 2020

Nginx – Enable PHP-FPM Status Page

PHP-FPM has a very useful built-in status page.

You can access it over web and also write scripts to monitor your PHP-FPM sites health remotely.

Enabling PHP-FPM Status Page

Edit PHP-FPM Config

In file /etc/php5/fpm/pool.d/www.conf, find pm.status_path variable.

vim +/pm.status_path /etc/php5/fpm/pool.d/www.conf

Uncomment that line (if its commented).

Default value is /status. You can change it to something else. May be you can add pool-prefix if you are running multiple PHP pools.

pm.status_path = /status

Edit Nginx config

Next, in Nginx config for example.com add a location block like below:

location = /status {
  access_log off;
  allow 127.0.0.1;
  allow 1.2.3.4#your-ip;
  deny all;
  include fastcgi_params;
  fastcgi_pass 127.0.0.1:9000;
}

location = /ping {
  access_log off;
  allow 127.0.0.1;
  allow 1.2.3.4#your-ip;
  deny all;
  include fastcgi_params;
  fastcgi_pass 127.0.0.1:9000;
}

Do not forget to replace your IP address. For security reasons, its better to keep your PHP-FPM status page private.

Reload PHP-FPM and Nginx config for changes to take effect.

PHP-FPM Status Sample

Default PHP-FPM Status Sample

Now, open http://example.com/status in browser to see summarised stats like below

pool:                 www
process manager:      dynamic
start time:           17/May/2013:13:54:02 +0530
start since:          886617
accepted conn:        1619617
listen queue:         0
max listen queue:     0
listen queue len:     0
idle processes:       28
active processes:     2
total processes:      30
max active processes: 31
max children reached: 0
slow requests:        0

Below is meaning of different values

Full PHP-FPM Status Sample

If you want detailed stats, you can pass argument ?fullto status page URL. It will become http://example.com/status?full

In additional to pool-level summary we have seen above, this will show extra details for per process. A sample is below:

pid:                  1419692
state:                Idle
start time:           27/May/2013:20:06:12 +0530
start since:          287
requests:             32
request duration:     188927
request method:       GET
request URI:          /feed.php?uid=12997446135571490564
content length:       0
user:                 -
script:               /var/www/example.com/htdocs/feed.php
last request cpu:     5.29
last request memory:  524288

Below is meaning of different values

Note: If the process is in Idle state, then informations are related to the last request the process has served. Otherwise informations are related to the current request being served.

PHP-FPM Status Page Output formats

By default the status page output is formatted as text/plain. Passing either ‘html’, ‘xml’ or ‘json’ in the query string will return the corresponding output syntax.

Examples for summary status page:

Example for detailed status page:

You can use json or xml format to process status page output programatically. HTML is useful when viewing detailed status report.


Comments

  1. getting bad gateway error

    1. Can you check error.log? Most likely in /var/log

      1. Chris Darts Avatar
        Chris Darts

        I’m also getting a 502 Bad Gateway error.

        This is the output from the error.log file:

        2014/01/09 08:09:52 [error] 7497#0: *9 connect() failed (111: Connection refused) while connecting to upstream, client: 127.0.0.1, server: magento, request: “GET /status HTTP/1.1”, upstream: “fastcgi://127.0.0.1:9000”, host: “www.mydomain.co.uk”

        1. Check if PHP FPM is running. Also check if both PHP and Nginx config are modified and both services restarted/reloaded.

          1. Chris Darts Avatar
            Chris Darts

            Yes PHP FPM is running.

            Just to clarify, I edited the default website config file in Nginx with the location code: /etc/nginx/sites-available/default

            I have restarted both PHP-FPM and nginx

          2. What is default domain name (server_name)?

            If default is IP, then you need use http://ip-address/status

            If its some domain like, example.com, you need use http://example.com/status

            I generally copy location block in main site’s nginx config.

          3. Chris Darts Avatar
            Chris Darts

            It’s a domain name http://www.explosivenutrition.co.uk

            Please clarify where to ‘use’ the domain name:

            “If its some domain like, example.com, you need use http://example.com/status

            Also, I’m not sure what you mean by the main site’s nginx config. Which file is this exactly?

            Thanks for your help.

          4. It depends on your server layout. By our conventions – http://rtcamp.com/wordpress-nginx/tutorials/conventions/

            Your server must have a file called /etc/nginx/sites-available/explosivenutrition.co.uk in which you will paste location block.

            If your layout is different, you just need to figure out correct server{..} block to add location{..} codes I provided in article.

          5. Chris Darts Avatar
            Chris Darts

            There isn’t a specific one for the domain name, instead it’s just set as ‘default’ – /etc/nginx/sites-available/default

            I forgot to mention the domain name is running a Magento site, not WordPress – does that make any difference?

          6. Assuming you are on Ubuntu:

            Install package – apt-get install libfcgi0ldbl

            Then copy-paste following codes:

            SCRIPT_NAME=/status \
            SCRIPT_FILENAME=/status \
            QUERY_STRING= \
            REQUEST_METHOD=GET \
            cgi-fcgi -bind -connect 127.0.0.1:9000

            If you do not see status output on command-line, then there is something wrong with PHP-FPM (either config or build).

          7. Chris Darts Avatar
            Chris Darts

            Thanks. If I try that I get the following:

            “Could not connect to 127.0.0.1:9000”

            I’ve noticed in the same nginx config file that there are references to a different port: fastcgi_pass 127.0.0.1:9001;

            However, when I try using 9001 instead I get a ‘file not found’ error.

            php-frm is definitely installed and working. It keeps causing the CPU to max out at 100% occasionally, which I why I’m trying to set-up the status access to see what’s going on.

          8. Chris Darts Avatar
            Chris Darts

            The PHP-FPM config is already set to ‘listen = 127.0.0.1:9000’

            Which Nginx file are you referring to by this “Next, open Nginx virtual-host config file(s).”

            Is that the same file where I added the ‘location’ block?

          9. Make sure nginx also uses 9000. About config files, it depends on your layout.

            Did you try this – https://rtcamp.com/tutorials/php/directly-connect-php-fpm/ ?

        2. Chris Darts Avatar
          Chris Darts

          The nginx config files have a number of refernces to port 9001 instead: fastcgi_pass 127.0.0.1:9001;

          So I changed the php-fpm http://www.conf to: listen = 127.0.0.1:9001

          They all now match, but instead of the bad gateway I’m getting a 404 file not found error.

          1. If PHP and Nginx ports are matching then something else must be wrong.

            If you can start afresh, try going with easyengine – https://rtcamp.com/easyengine

  2. No problem getting it to work. Now that I/we can see the stats, what exactly are we on the lookout for?

    While the definitions are given for each term, it is not exactly clear what good numbers are and what bad numbers are, nor what to do should we encounter bad numbers. Like if ‘x’ term = ‘xyz’ then increase this value etc..

    1. Most values are just informative.

      We try to make sure that “max children reached” remains 0 (zero).

      Also you can be concerned about “slow requests” if you have enabled PHP-FPM slowlog – https://rtcamp.com/tutorials/php/fpm-slow-log/

  3. Very nice description. Thank you

  4. Hello,

    After following the above instructions, I receive the following error upon restarting nginx:

    nginx: [emerg] no port in upstream “php” in /etc/nginx/nginx.conf:72

    I’m running this on Arch Linux ARM. I tried replacing “php” with “127.0.0.1:9000” in the offending line, which eliminated the error; however, the resulting php-fpm status page was simply blank. (I tried “127.0.0.1:9000” because it’s used in another “location” block statement, “fastcgi_pass 127.0.0.1:9000;“).

    Any ideas how to fix this?

    buzz

    1. Just open file /etc/nginx/nginx.conf and jump to line 72

      Most likely you will find upstream {..} block there. You can delete it and try again.

      1. Hello Rahul,

        Line 72 of the /etc/nginx/nginx.conf file is:

        fastcgi_pass php;

        This is the line from your instructions above. The “php” element in this statement is causing problems. Why?

        buzz

        1. Use fastcgi_pass 127.0.0.1:9000;

          For fastcgi_pass php; to work you need to have upstream php block elsewhere.

          I will update this article.

  5. Hello, slow requests doesn’t appear in status after I turn on slow log:

    slowlog = /var/log/php5/slow.log

    request_slowlog_timeout = 10s

    Probably I need something else to do, to se it ?

    1. It could be because every request is getting completed in less than 10s.

      Try setting a value to 1s. If that doesn’t work, then there could be an issue with config.

      Also check if file /var/log/php5/slow.log exists physically on disk.

  6. Hi, thanks for this neat tip. I was not aware if this neat PHP5-FPM feature.

    Small remark: There seem to be missing some trailing “;” signs in the nginx site conf code. Plus it might be helpful to mention the use of “unix:/var/run/php5-fpm.sock” for those that followed other tutorials on this site 🙂

    1. By the way, what that “ping” in location ~ ^/(status|ping)$ for?

      1. If your goal is to check if PHP-FPM is replying to request only, you can open /ping path and see if it returns pong.

        It may sound funny but if you have external process monitoring your FPM, such a short reply can reduce bandwidth. Though I think, in practise /status output will also fit in single packet. May be FPM need to do some calculation to return /status but for /ping/ it returns a predefined string only.

        1. Cool ! Never thought of such usage. Very useful 🙂

    2. I updated article for missing ;.

      I will update cross-check all tutorials for unix:/var/run/php5-fpm.sock.

      Our internal convention is to have upstream { } block for PHP backend so we keep adding/removing FPM pools and sometimes use mix of tcp/ip and unix-based sockets.

      I will try to stick to one method and update all articles soon.

  7. Hi ,
    ‘full’ option is not working. I am just getting the basic stats.Any ideas why?
    Here is my location section

    location ~ ^/(fpmstatus|ping)$ {
       access_log off;
       allow 127.0.0.1;
       allow  ;
       deny all;
       include        /usr/local/nginx/conf/fastcgi_params;
       fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
       fastcgi_pass 127.0.0.1:9000;
    }

    Thanks.

    1. I think following line is not needed:

      fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;

      Please use my config from article above.

  8. Thanks for the set of good instructions. It also got the PHP-FPM ping/pong test working so that I could set up an alert on Copperegg.com to warn if it goes down.

  9. Hi, i did everything as this tutorial but when i request /status i get just a BLANK page.
    I have restarted all services and the logs of nginx and php-fpm doesn’t contain anything related … don’t know what to do

    1. Try removing access_log off; and see if your hits to /status are reaching nginx.

      Most likely it could be mismatch with pm.status_path = /status in /etc/php5/fpm/pool.d/www.conf

    2. Yuriy Bychenok Avatar
      Yuriy Bychenok

      Try this one

      location ~ ^/(status|ping|apc_info.php)$ {
      include fastcgi_params;
      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
      fastcgi_pass backend;
      allow 127.0.0.1;
      deny all;
      }

  10. For those who are getting a gateway error upon using this guide, this is due to PHP5-FPM unable to create the log files needed, so make sure that you create the folders and files for your logs as per http://www.conf and php5-fpm.conf before you complete this guide.

    For example for the following paramters:

    access.log = /var/log/php5-fpm/access.log in http://www.conf
    slowlog = /var/log/php5-fpm/slow.log in http://www.conf
    error_log = /var/log/php5-fpm/daemon.log in php5-fpm.log

    You would need to create the folders yourself for /var/log/php5-fpm/ as the default parameters link to a non-existing path for some reason on ubuntu.

    1. You cannot get php restart error after following this article which is related to log files.

      This article doesn’t change any log file path so how can it complain about folder creation?

      Looks like you have mixed instructions from multiple sources.

      1. That’s what I thought, but the default path log/php5-fpm.log was inaccessible, and the error the guys are complaining about in the comments disappeared after I fixed it to a path that exists.

        1. That path has nothing to do with this article.

          Anyway, default `log/php5-fpm` refers to `/var/log` which is created by OS. I did not asked to change log path in this article.

          Only line which is sensitive in this article is: `fastcgi_pass 127.0.0.1:9000;`

          If somebody has FPM listening on other port/socket, they need to change this line.

          1. Then it might be that my php5-fpm did not have access to create the file php5-fpm.log, which is why it worked when I created it.