FeaturesWP CloudPricingEE CLIContactMy Account
Features
Team Access & User Permissions
Install
Resources
Community
CLEAR
Tutorials
PHP
Nginx – Enable PHP-FPM Status Page
Topics
On this page
-
- Getting Started
- Git and File-System Layout (non-default setup)
- Version Constraints
- Managing Themes and Plugins (for entire WordPress site)
- Updating Themes and Plugins (for entire WordPress site)
- Adding Composer Support to Your Own Themes and Plugins (for developers)
- Using Composer to Manage Own Theme/Plugin Dependencies (for developers)
-
- Assigning Multiple IP Addresses to Single LAN Card
- Disable IPv6 on Ubuntu 12.04
- dsh – distributed shell
- fdupes – find & replace duplicate files with hardlinks
- GPG Keys Cheatsheet
- Increase "Open Files Limit"
- kill all php, nginx, mysql or any kind of processes
- Passwordless Authentication for SSH
- Screen
- search replace in multiple files useing grep xargs sed
- Setup sftp
- sysctl.conf
- Timezone Sync
- Using Google Public DNS on Ubuntu Server
- Using openssl to match private key, cerificate and CSR
- Configure Postfix to Use Gmail SMTP on Ubuntu
- Logrotate Example for Custom Logs
- PHP 5.5, MySQL, Postfix, Nginx and WordPress on Ubuntu
- Serverdensity
- Upgrade Ubuntu 10.04 to 12.04
- Using find and sed to replace strings in multiple files
- Webmin
-
- .my.cnf – mysql user & password
- Analyse slow-query-log using Anemometer
- Improving MySQL Query Cache
- MySQL Query Profiling
- Reset MySQL root password
- tuning-primer.sh – an alternative for mysqltuner
- Using MariaDB 10
- Install/Upgrade to MySQL 5.6 on Ubuntu 12.04 LTS
- Change WordPress Domain Name
- Character Sets and Collations
- Enable innodb_file_per_table
- Enable Remote Access (Grant)
- Installing Percona Toolkit
- Using tmpfs for temporary folder creation
- YARPP and InnoDB
- Convert MyISAM to InnoDB
- Using tmpfs for mysqldump & mysqlimport
- Convert from INNODB to MYISAM
- Analyse slow-query-log using mysqldumpslow & pt-query-digest
- mysqlcheck with cron to optimize automatically
- Using MySQLTuner to Optimize MySQL configuration
-
-
- Directly connect to PHP-FPM
- Generating core-dump for php5-fpm
- GeoIP
- Having php5 and php7 on same system.
- Install Xdebug and configure it with webgrind
- Installation of PHP Code Review Tools
- memcache
- PHP's Zend Opcache Config & Web Viewer
- Setting Sqlite support with PHP
- Using HHVM with PHP-FPM Fallback
- Using Redis for PHP Sessions on Ubuntu Server
- Installing PhpMyAdmin Quickly
- Moving PHP's session storage to tmpfs
- Install Xdebug and configure it with Netbeans
- Nginx – Enable PHP-FPM Status Page
- PHP-FPM: Socket vs TCP/IP and sysctl tweaking
- APC Cache Optimization & Monitoring Using Web Interface
- Checking if PHP/WordPress can send mails
- Debugging PHP Scripts Using slow_log and more
- Increase file upload size limit in PHP-Nginx
- Increase PHP script execution time with Nginx
-
- Performance Optimization
- Remove Query string of css/js files
- Setup ElasticSearch with ElasticPress
- Using Redis for WordPress Object-Cache
- WooCommerce Window Shopping Caching Technique
- Moving WordPress To New Server (Faster)
- Better wp-cron using linux's crontab
- 404 error- Page not Found!!!
- Debugging WordPress with Nginx
Enabling PHP-FPM Status Page
Edit PHP-FPM Config
Edit Nginx config
PHP-FPM Status Sample
Default PHP-FPM Status Sample
Full PHP-FPM Status Sample
PHP-FPM Status Page Output formats
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
- pool – the name of the pool. Mostly it will be www.
- process manager – possible values static, dynamic or ondemand. We never use static. Trying ondemand is on todo list.
- start time – the date and time FPM has started or reloaded. Reloading PHP-FPM (
service php5-fpm reload) reset this value. - start since – number of seconds since FPM has started
- accepted conn – the number of request accepted by the pool
- listen queue – the number of request in the queue of pending connections. If this number is non-zero, then you better increase number of process FPM can spawn.
- max listen queue – the maximum number of requests in the queue of pending connections since FPM has started
- listen queue len – the size of the socket queue of pending connections
- idle processes – the number of idle processes
- active processes – the number of active processes
- total processes – the number of idle + active processes
- max active processes – the maximum number of active processes since FPM has started
- max children reached – number of times, the process limit has been reached, when pm tries to start more children. If that value is not zero, then you may need to increase max process limit for your PHP-FPM pool. Like this, you can find other useful information to tweak your pool better way.
- slow requests – Enable php-fpm slow-log before you consider this. If this value is non-zero you may have slow php processes. Poorly written mysql queries are generally culprit.
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
- pid – the PID of the process. You can use this PID to kill a long running process.
- state – the state of the process (Idle, Running, …)
- start time – the date and time the process has started
- start since – the number of seconds since the process has started
- requests – the number of requests the process has served
- request duration – the duration in µs of the requests
- request method – the request method (GET, POST, …)
- request URI – the request URI with the query string
- content length – the content length of the request (only with POST)
- user – the user (PHP_AUTH_USER) (or ‘-‘ if not set)
- script – the main PHP script called (or ‘-‘ if not set)
- last request cpu – the %cpu the last request consumed. it’s always 0 if the process is not in Idle state because CPU calculation is done when the request processing has terminated
- last request memorythe max amount of memory the last request consumed. it’s always 0 if the process is not in Idle state because memory calculation is done when the request processing has terminated
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:
- 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.
Install Xdebug and configure it with Netbeans
PREVIOUS
PHP-FPM: Socket vs TCP/IP and sysctl tweaking
NEXT
Comments
-
getting bad gateway error
-
Can you check
error.log? Most likely in/var/log-
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”
-
Check if PHP FPM is running. Also check if both PHP and Nginx config are modified and both services restarted/reloaded.
-
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
-
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.
-
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.
-
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.ukin which you will paste location block.If your layout is different, you just need to figure out correct
server{..}block to addlocation{..}codes I provided in article. -
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?
-
Assuming you are on Ubuntu:
Install package –
apt-get install libfcgi0ldblThen copy-paste following codes:
SCRIPT_NAME=/status \ SCRIPT_FILENAME=/status \ QUERY_STRING= \ REQUEST_METHOD=GET \ cgi-fcgi -bind -connect 127.0.0.1:9000If you do not see status output on command-line, then there is something wrong with PHP-FPM (either config or build).
-
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.
-
Make sure PHP-FPM and Nginx agree on socket values.
Ref – https://rtcamp.com/tutorials/php/fpm-sysctl-tweaking/
Also https://rtcamp.com/tutorials/linux/increase-open-files-limit/ and https://rtcamp.com/tutorials/linux/sysctl-conf/ might help to reduce CPU load.
-
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?
-
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/ ?
-
-
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.
-
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
-
-
-
-
-
shawn
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..
-
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/
-
-
Juraj
Very nice description. Thank you
-
buzz
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
-
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.-
buzz
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
-
Use
fastcgi_pass 127.0.0.1:9000;For
fastcgi_pass php;to work you need to haveupstream phpblock elsewhere.I will update this article.
-
-
-
-
andry
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 ?
-
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.logexists physically on disk.
-
-
RavanH
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 🙂
-
RavanH
By the way, what that “ping” in
location ~ ^/(status|ping)$for?-
If your goal is to check if PHP-FPM is replying to request only, you can open
/pingpath and see if it returnspong.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
/statusoutput will also fit in single packet. May be FPM need to do some calculation to return/statusbut for/ping/it returns a predefined string only.-
RavanH
Cool ! Never thought of such usage. Very useful 🙂
-
-
-
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.
-
-
Rajesh
Hi ,
‘full’ option is not working. I am just getting the basic stats.Any ideas why?
Here is my location sectionlocation ~ ^/(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.
-
I think following line is not needed:
fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;Please use my config from article above.
-
-
Conrad
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.
-
endri
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-
Try removing
access_log off;and see if your hits to/statusare reaching nginx.Most likely it could be mismatch with
pm.status_path = /statusin/etc/php5/fpm/pool.d/www.conf -
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;
}
-
-
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.logYou 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.
-
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.
-
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.
-
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.
-
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.
-
-
-
-
Features
- Server Setup & Management
- Site Creation & Management
- Create WP Cloud Sites
- Speed & Caching
- Firewall Protection
- Backups & Recovery
- Logs & Monitoring
- Deployments & Developer Tools
- Team Access & User Permissions
Useful Links
Product
Other Products
Subscribe for curated product updates, tips, and announcements.
"*" indicates required fields
Company
This field is for validation purposes and should be left unchanged.
Email*
SIGN ME UP
Δ
© rtCamp, since 2009. All rights reserved.