Magento and PHP generate log files in var/log/ and server logs may also collect traffic,
errors, and exceptions. Without log rotation, these files grow indefinitely and can fill disk space,
causing outages or data loss.
Log rotation ensures logs are archived or truncated on schedule. It prevents storage exhaustion, keeps logs manageable, and makes monitoring systems more reliable.
# Check logrotate configuration for Magento logs
cat /etc/logrotate.d/magento
# Example entry should rotate system.log and exception.log
# Inspect log file sizes
ls -lh var/log/
# If files grow endlessly without rotation → FAIL
/var/www/magento/var/log/*.log {
weekly
rotate 12
compress
missingok
notifempty
create 640 magento www-data
sharedscripts
postrotate
systemctl reload php8.2-fpm >/dev/null 2>&1 || true
endscript
}
# var/log/system.log keeps growing to 5GB
-rw-r--r-- 1 magento www-data 5.0G Jan 20 12:00 system.log
# No rotation → FAIL
# var/log/system.log rotated weekly
-rw-r----- 1 magento www-data 20K Jan 20 12:00 system.log
-rw-r----- 1 magento www-data 200K Jan 13 12:00 system.log.1.gz
# Rotation working → PASS