Questions? Feedback? powered by Olark live chat software
Knowledgebase
Author Avatar

cPanel PHP-FPM php error log rotation

Written by: on 20 May 2021 12:19 PM 20 May 2021 12:19 PM

How to set up PHP error log rotation in cPanel


When cPanel server uses PHP-FPM it does only control the log rotation for system-like log files, which are sitting at /opt/cpanel/ea-phpXY

However it does not rotate PHP error log generated and stored at /home/<user>/logs/domain.com.php.error.log

Modern CMSes may produce huge amount of Warning and Deprecated log entries in those files.

To setup log rotation for mentioned log files you need to create a new logrotate unit.

Example file name: /etc/logrotate.d/custom_php-fpm_error_log

File content:
/home/*/logs/*php.error.log {
	daily
	rotate 3
	missingok
	notifempty
	compress
	create
}
This unit will run daily, rotate log file, compress it, keep last 3 rotated files, and create a new empty log file with correct owner/permissions.
(4 vote(s))
Helpful
Not helpful