How can I automatically delete old apache error log files?

Solution 1:

Yes, it's safe to delete the files though deleting the current file doesn't generally do what you expect.

By default Ubuntu uses logrotate Take a look at your /etc/logrotate.d/apache2 file, you'll probably find that is has a line like

rotate 52

This means it will keep 52 copies of your rotated log files. Change this number to the number you want to keep. This will though work on all the apache2 logs if you want to just do the error log then split it out and give it it's own rules.