May 05, 2016

Logrotate for Forge

The logs for your applications on Forge can get large - see how to manage their size automatically using logrotate!

Laravel Forge (and Envoyer) keep your Laravel application's storage directory persistent through deployments. One side effect of this is that your storage/logs/laravel.log file is always growing.

Linux systems come with Logrotate, which can help us manage your growing log files. It's really simple - we can basically set it and forget it.

Note: This is best used when your logs are set to single rather than daily within your config/app.php file.

Logrotate for Forge

First, we need to know the application's log storage directory. If my application is, that location is likely /home/forge/

Knowing that, we can make a logrotate configuration for it at /etc/logrotate.d/

/home/forge/*.log {
    su forge forge
    rotate 24
    create 755 forge forge

Once you save that file, you're done!

Let's go over the options we set there:

  • First we set the file path, and tell it to find any file ending in .log
  • su forge forge tells logrotate to use user/group forge to process these logs
  • weekly tells logrotate to rotate logs weekly (versus daily, monthly, yearly)
  • missingok - If no *.log files are found, don't freak out
  • rotate 24 - Keep 24 files before deleting old log archived (deletes oldest first). This is 24 weeks, or 6 months
  • compress - Compress archived log files so they take less disk space
  • notifempty - Don't rotate the log if it's empty
  • create 755 forge forge - Create new log files with these permissions/owner settings


To test this command out, we can force the running of logrotate with the following command:

# Forge logrotate to run against config file
sudo logrotate --force

This will tell you if there are any errors. If you get no output, you should be able to check your log directory and see some newly rotated logs!


All Topics