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 !
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 !
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.
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.
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
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.
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.
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
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)