Introduction
How to configure the PHP-FPM slow log.
Please ensure that you have PHP FPM enabled for your desired domains before attempting the following configuration.
TIMEOUT NOTE:
The configuration below sets the slowlog timeout to 1 second so that you can easily test your site to ensure that the log is working. You should modify the timeout configuration so that it meets your own needs, otherwise, the log could grow to become very large.
LOG ROTATION NOTE:
The log that is generated could quickly become very large and use all the disk space on your server. If you plan on leaving the slow log active for any amount of time, you should set up log rotation to maintain the log. Please see the man page for logrotate if you have questions about how to do this:
https://linux.die.net/man/8/logrotate
Setup Slowlog For All Domains on the server
- Login to the server via SSH or Terminal as the root user
- Create the system pool defaults file if it does not already exist:
mkdir /var/cpanel/ApachePHPFPM/
touch /var/cpanel/ApachePHPFPM/system_pool_defaults.yaml
- Ensure that the log directory exists:
mkdir /var/log/php-fpm/
- Add the following contents to the file (please note that these configuration options will need to be added within the top and bottom "---" lines):
---
_is_present: 1
slowlog: { name: 'slowlog', value: "/var/log/php-fpm/slow.log" }
request_slowlog_timeout: { name: 'request_slowlog_timeout', value: 1 }
- Rebuild the PHP FPM configuration:
/usr/local/cpanel/scripts/php_fpm_config --rebuild
- Run a check to verify that FPM is still up and running:
/scripts/restartsrv_apache_php_fpm --status
- Tail the newly created log:
tail -fn0 /var/log/php-fpm/slow.log
- Then visit your site on a page that is slow
Setup Slowlog for a single domain
NOTE: The domain-specific configuration overrides the system_pool_defaults.yaml configuration above.
- Login to the server via SSH or Terminal as the root user
- Open the domain's PHP-FPM YAML template file. Replace the example portions in the below file with your own domain and cpanel username:
/var/cpanel/userdata/cpanelexampleusername/example.com.php-fpm.yaml
- Set the file's contents to the following:
---
_is_present: 1
slowlog: { name: 'slowlog', value: "/var/log/php-fpm/slow.log" }
request_slowlog_timeout: { name: 'request_slowlog_timeout', value: 1 }
- Rebuild the PHP FPM configuration:
/usr/local/cpanel/scripts/php_fpm_config --rebuild
- Run a check to verify that FPM is still up and running:
/scripts/restartsrv_apache_php_fpm --status
- Tail the newly created log:
tail -fn0 /var/log/php-fpm/slow.log
- Then visit your site on a page that is slow