How To Configure Logging And Log Rotation In Apache On An Ubuntu VPS

How To Configure Logging And Log Rotation In Apache On An Ubuntu VPS

How To Configure Logging And Log Rotation In Apache On An Ubuntu VPS

In this tutorial, you will learn how to configure logging and log rotation in Apache on an Ubuntu VPS.

Prerequisites

  • An Ubuntu VPS
  • Apache installed and running

Step 1: Enabling Logging

The first step in configuring logging is to enable it in Apache. To do this, you need to modify the Apache configuration file.

Open the Apache configuration file using your preferred text editor:

sudo nano /etc/apache2/apache2.conf

Add the following lines to enable logging:

LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined CustomLog ${APACHE_LOG_DIR}/access.log combined

Save and close the file.

Step 2: Configuring Log Rotation

Log rotation is the process of automatically managing log files to prevent them from using up too much disk space. To configure log rotation, you need to create a new configuration file.

Create a new file called "apache2" in the logrotate.d directory:

sudo nano /etc/logrotate.d/apache2

Add the following lines to configure log rotation:

/var/log/apache2/*.log { daily missingok rotate 14 compress delaycompress notifempty create 640 root adm sharedscripts postrotate /etc/init.d/apache2 reload > /dev/null endscript }

Save and close the file.

Step 3: Restarting Apache

After making changes to the Apache configuration, you need to restart Apache to apply the changes:

sudo systemctl restart apache2

That's it! You have successfully configured logging and log rotation in Apache on your Ubuntu VPS.

Keywords: - logging - log rotation - Apache - Ubuntu VPS - configuration file - text editor - LogFormat - access.log - logrotate.d - daily rotation - compress - delaycompress - notifempty - create - sharedscripts - postrotate - systemctl restart

Комментарии

Популярные сообщения из этого блога

How To Modify CSS Classes in JavaScript

How To Backup MySQL Databases on an Ubuntu VPS

How To Backup PostgreSQL Databases on an Ubuntu VPS