Setting up logrotate

servers Aug 30, 2020

It is important to set up log rotation, as otherwise extensive logging could lead to the HDD being full (and the server going down).

For every type of entry you want to rotate, you should add a separate file in /etc/logrotate.d:

For example to rotate all symfony projects in a given directory:

/var/data/www/*/var/log/*.log {
    rotate 7

All settings explained:

  • daily: rotate daily
  • missingok: don't error if the file is missing
  • rotate 7: keep 6 old files + the current one
  • compress: compress the log after rotating
  • notifempty: don't archive an emoty file, if the current one is empty
  • create: Creates a new file. This can optionally take a bitmask of file permissions and a user and a group (`create 0644 user group`). But all omitted values are recreated like they are on the current file, so in our case: keep the user, group and file permissions the same.

Photo credit: Mae Mu