Log won't rotate

I can’t make the log rotate properly. Not sure why.
I moved the log to /var/log/nextcloud.log (in the config.php). then had to create that file and give it the (hopefully) right permissions or else it couldn’t be created:
-rw-r----- 1 www-data www-data 16M Jun 25 17:15 nextcloud.log

Then it wanted to create nextcloud.log.1 but couldn’t so I had to create that one too:
-rw-r----- 1 www-data www-data 0 Jun 25 16:31 nextcloud.log.1

Now when the 10 mb are full it gives me the error below and nextcloud.log.1 stays empty.


{"reqId":"B+khwHHGDKU0vvt6P8l2","remoteAddr":"","app":"PHP","message":"rename(\/var\/log\/nextcloud.log,\/var\/log\/nextcloud.log.1): Permission denied at \/var\/www\/nextcloud\/lib\/private\/log\/rotate.php#46","level":3,"time":"2016-06-25T17:15:01+02:00","method":"--","url":"--","user":"--"}
{"reqId":"B+khwHHGDKU0vvt6P8l2","remoteAddr":"","app":"OC\\Log\\Rotate","message":"Log file \"\/var\/log\/nextcloud.log\" was over 10485760 bytes, moved to \"\/var\/log\/nextcloud.log.1\"","level":2,"time":"2016-06-25T17:15:01+02:00","method":"--","url":"--","user":"--"}


'loglevel' => 2,
'logfile' => '/var/log/nextcloud.log',
'log_rotate_size' => 10485760,`

What did I do wrong?

Your webserver user doesn’t have the permission to create new files in /var/log. For apache and other processes the log rotation is done by a system cronjob. You have two options:

  • Let the system-cronjob also do the rotation of your owncloud.log. Create a new file /etc/logrotate.d (check the man pages of logrotate about all the options):
    /var/log/owncloud.log {
    rotate 14
    create 640 root adm
  • Put your owncloud-logfiles in a location where www-data has the permission to write, e.g. /var/log/owncloud