Skip to content

Rotate Apache Logs

To set up log rotation for Apache (httpd) on all app servers in company-name Datacenter, follow these steps:

1. Install Apache (httpd)

Run the following command on each app server:

sudo yum install httpd -y
sudo systemctl start httpd
sudo systemctl enable httpd

This installs and starts Apache, ensuring it runs on boot.

2. Configure Log Rotation for Apache

Edit or create a logrotate configuration file for Apache:

sudo nano /etc/logrotate.d/httpd

Add the following configuration:

/var/log/httpd/*.log {
    monthly
    rotate 3
    compress
    missingok
    notifempty
    create 0640 root root
    sharedscripts
    postrotate
        systemctl reload httpd > /dev/null 2>&1 || true
    endscript
}

3. Test Log Rotation

Run:

sudo logrotate -d /etc/logrotate.d/httpd

This dry-run ensures the configuration is correct.

4. Verify Log Rotation

Check rotated logs:

ls -lh /var/log/httpd/

You should see compressed logs (.gz) with only 3 rotated versions.

For more details, check out this guide or this discussion. Let me know if you need further customization! 🚀