Next up, we need to take care of the error logs. We do this in the exact same way as we rotated the access logs, starting with setting up the file names.
$error_file = "mywebsite.com-error_log";Then using the system function, we move the original file to the new archive name, and tar and zip the file to create the actual archive zip file.
$error_archivefile = strftime("$error_file.%Y-%m-%d", localtime);
$error_archivezip = "$error_archivefile.tar.gz";
system "mv $error_file $error_archivefile";Next, let's delete the un-zipped archive file and mv the zipped one on into the archives directory.
system "tar -czf $error_archivezip $error_archivefile";
system "rm $error_archivefile";Last but not least, we'll restart the web server using the apachectl script - you should note that depending on your configuration and server, this part will probably be different on your machine. The important thing to do it restart the server, however it's done, so that the log files can be re-created as blanks.
system "mv $error_archivezip archives/";
`/usr/local/apache2/bin/apachectl restart`;Previous: Rotating the access log

