Site icon David Yin's Blog

Enable PHP-FPM Status Page with Nginx

I have been using PHP-FPM to interpret the PHP language program for years.  My server or VPS is powered by Ubuntu, most time the latest LTS version or the second latest version. I like Nginx for web servers. In the title I said php-fpm. It could be php8.2-fpm, php8.1-fpm. The different version of php-fpm has different names.

Now this post is about how to add the PHP-FPM status page to the web.

Enable php-fpm Status page

SSH to the VPS, find the file, /etc/php/8.2/fpm/pool.d/www.conf

sudo nano www.conf

Located pm.status_path = /status

Remove the # to un-comment it.

Then run the command to restart the php8.2-fpm service.

sudo service php8.2-fpm restart

Edit the Nginx Web server settings

My website configuration files are located in /etc/nginx/conf.d/

sudo nano mysite.conf

Add following into the server block.

location ~ ^/(status|ping)$ {
access_log off;
allow 127.0.0.1;
allow your-ip-address;
deny all;
fastcgi_index /php-fpm/status;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_pass unix:/var/run/php/php8.2-fpm.sock;
# fastcgi_pass 127.0.0.1:9000;
}

Look at the code above carefully.
1) Replace your-ip-address with your IP address. It will only allow you to access this status page.
2) Choose the way you use php-fpm. I am using a socket connection. If you are using a TCP connection, you should modify the code above.

Then restart the Nginx server.

sudo service nginx restart 

Go to the desktop browser to load the status web page.

pool:                 www
process manager:      dynamic
start time:           20/Jan/2024:00:54:13 -0800
start since:          51012
accepted conn:        24883
listen queue:         0
max listen queue:     0
listen queue len:     0
idle processes:       2
active processes:     1
total processes:      3
max active processes: 3
max children reached: 0
slow requests:        0

 

There are also more details status page.
Examples for summary status page:

http://example.com/status
http://example.com/status?json
http://example.com/status?html
http://example.com/status?xml

Example for detailed status page:

http://example.com/status?full
http://example.com/status?json&full
http://example.com/status?html&full
http://example.com/status?xml&full

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

The PHP official docs page.

Definations

Here is a sample of full detailed status page in HTML format.


Meaning of the items.

Getting the php8.2-fpm status page is one of the steps to prepare for php optimization. I need more data to analyze and make a decision.

Exit mobile version