← Back to Baseline

Why it Matters

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.

Verification Steps

Linux system check

# Check logrotate configuration for Magento logs
cat /etc/logrotate.d/magento

# Example entry should rotate system.log and exception.log

Manual check

# Inspect log file sizes
ls -lh var/log/

# If files grow endlessly without rotation → FAIL

Remediation / Fix Guidance

  1. Create a logrotate rule for Magento logs:
    /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
    }
  2. Verify system logrotate is running (cron or systemd timer).
  3. Ensure rotated logs are archived securely and old logs are deleted when no longer needed.

Examples

Fail Example
# 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
Pass Example
# 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

References