skip to Main Content

I have discovered that my access_log is occupying most of my HDD. It’s over 200 GB in size. How can I reset it ?

I am using Apache 2.2.3 on a CentOS server with Plesk.

Thank you guys !

8

Answers


  1. Rename the file to different filename and create new file with the name access_log and restart apache (otherwise apache keeps the lock on the file and don’t “see” the file change)

    Login or Signup to reply.
  2. Use the logrotate daemon in order to have a clean maintenance of your logs, specially, the apache related logs.

    A brief info about logrotate: http://www.scriptinstallation.in/logrotate.html

    Login or Signup to reply.
  3. Rename the file, create a new access_log, then restart Apache.

    Login or Signup to reply.
  4. If you have access by SSH to the server, then you can:

    1) Gzip the old file (text files compression ratios are really good). If we assume the file is named /var/log/apache/access.log then do this:

    gzip -c /var/log/apache/access.log > /var/log/apache/access.log.gz

    2) Clear the current file

    echo > /var/log/apache/access.log

    3) Restart apache

    Also as Dez has suggested consider using logrotate for production grade apache log archiving.

    Login or Signup to reply.
  5. knx’answer is good, but I would suggest to rename the log, and create a new one, so that you can restart apache without waiting for the access log to be compressed, which can take a while if it’s big.

    needs access to ssh

    First, rename the current log file:

    mv /var/log/apache/access.log /var/log/apache/access.log.1
    

    Second, create a new log file and give the same permissions, owner/group and selinux context as the original one:

    touch /var/log/apache/access.log
    chown --reference=/var/log/apache/access.log.1 /var/log/apache/access.log
    chmod --reference=/var/log/apache/access.log.1 /var/log/apache/access.log
    restorecon --reference=/var/log/apache/access.log.1 /var/log/apache/access.log
    

    (probably need to be root to do that)

    Next, restart apache

    Then Gzip the old file (text files compression ratios are really good). If we assume the file is named /var/log/apache/access.log then do this:

    gzip -c /var/log/apache/access.log.1 > /var/log/apache/access.log.1.gz
    

    these 4 points are what logrotate do automatically.

    Login or Signup to reply.
  6. If on Ubuntu do:

    sudo su
    cd /var/log/apache2
    rm access.log
    rm error.log
    touch access.log
    

    When creating that access log it magically starts the error log too.

    Login or Signup to reply.
  7. I know this post is ages old, but I just had same problem and no answer covers it correctly.

    The point is the apache creates the file as access_log, according to its configuration. However, logrotate only looks for *.log, hence the name does not match the search pattern.

    Solutions: Either you add *_log to logrotate configuration, or change the apache configuration to make it create the log file named access.log. Changing apache configuration requires apache reload.

    Login or Signup to reply.
  8. A simple solution is to disable access_log, commenting only one line on the configuration file.

    Source: https://www.mydigitallife.info/how-to-disable-and-turn-off-apache-httpd-access-and-error-log/

    For Plesk users:
    https://stackoverflow.com/a/41000240/1792240

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search