Adding a logrotation for your custom vhost apache logs

On the Virtual Hosts page there is line about having custom logs for your host but they will not be in logrotation by default. The logroatate guide is also helpful, but unconnected to the vhost setup. If anyone see's any errors, please comment.

~~[" target="blank">]( … tual-hosts">](

~~[" target="_blank">]( … /logrotate">](

Maybe it will help someone.


The service logrotate is pretty straight forward. My logs are made by apache so there are some extra stuff that has to be included. This is not realy a script as much as a small directive file. This file is named mycustomfile and it is placed in the /etc/logrotate.d/ folder. I don't think it matters what the name of the file is. It will be added to what logrotate daemon does. The following example assumes you followed the directions on setting up your vhosts in the linode library.

/home/example_user/public/*.log {
        rotate 52
        create 640 root root
                if [ -f "`. /etc/apache2/envvars ; echo ${APACHE_PID_FILE:-/var/run/}`" ]; then
                        /etc/init.d/apache2 reload > /dev/null


The opening line shows the location of the logs with a wildcard statement.

weekly - Run Weekly

missingok - If the file isn't there for a sec, don't sweat it.

compress - compress the old files delaycompress - only compress the file after enough time elapses for apache to restart and start seeing the new file.

notifyempty - don't rotate it if it is empty create 640 root root - create the new file with 640 privs and root user and group

sharedscripts - run once for each

the last bit tells the apache service to restart so that it will start using the new log file.

(Everything about the naming of the files and backups should be automatic.)


You may want to run tests in verbose mode that actually don't run the log rotation. Remove the "d" which is test mode and replace that with a "f." F will FORCE running even if the scrip calls for running on certain days.


logrotate -vd /etc/logrotate.d/yourcustomdirective

For Real

logrotate -vf /etc/logrotate.conf/yourcustomdirective

0 Replies


Please enter an answer

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct