Due to work requirements, it is necessary to set apache logs to be saved every day. Now I will share the specific method for your reference.
1. Search rotatelogs
rotatelogs is a module that apache comes with to generate logs by date. The specific location is subject to the rotatelogs location on your own website
[root@localhost ~]# find / -name rotatelogs /usr/sbin/rotatelogs
2. Modify /etc /httpd/conf/httpd.conf configuration file
Mainly modify two parts
#ErrorLog logs/error_log #注释此行,添加下面这行 ErrorLog "|/usr/sbin/rotatelogs /var/log/httpd/error_log%Y%m%d.log 86400 480" #CustomLog logs/access_log common #注释此行,添加下面这行 CustomLog "|/usr/sbin/rotatelogs /var/log/httpd/access_log%Y%m%d.log 86400 480" common
3. Restart Apache
[root@localhost ~]# systemctl restart httpd.service
4. Revisit to see the effect
[root@localhost ~]# cat /var/log/httpd/ access_log access_log20200504.log error_log error_log20200504.log
Related recommendations: apache tutorial
The above is the detailed content of How to set up apache to save logs every day. For more information, please follow other related articles on the PHP Chinese website!