Configuring Apache Virtual Host log rotation

Log rotation was not applied to my Apache Virtual Host access.log on my Raspberry Pi. I later found out the problem was just a small configuration mistake.

Default Apache log rotation configuration

Apache’s log rotation configuration can be found at /etc/logrotate.d/apache2.

If you take a look at it, the folder path is set to /var/log/apache2/*.log and keeping 14 rotations.

My Apache Virtual Host log configuration

My mistake was creating subfolders under /var/log/apache2/, one for each vhost and configured each vhost to store access.log and error.log into their respective folders.


I could alter my logrotate to include these subfolders but I felt that I may forget about this someday if I ever need to re-setup thus I adopted a simpler solution, storing vhost logs in /var/log/apache2/ with filenames prefixed by vhost domain. Example:

ErrorLog ${APACHE_LOG_DIR}/www.leowkahman.com_error.log
CustomLog ${APACHE_LOG_DIR}/www.leowkahman.com_access.log combined

Then, reload Apache for the new configuration to take effect using:

sudo service apache2 reload