Skip to content

phyex0/Apache2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 

Repository files navigation

Apache2

Storing Apache2 Logs

Step1: Installing Apache2 server:

sudo apt update

sudo apt install apache2

sudo echo "ServerName localhost" >> /etc/apache2/apache2.conf

sudo nano /etc/apache2/ports.conf # replace the Listen 80 with the 8079

sudo service apache2 start

Step2: Writing a bash script that checks the APACHE2 servers logs and compress them

nano apache2_log_compress.bash

    #!/bin/bash
    compress () {
            if [ "$(wc -l < $1)" -ge 20 ]
            then
                    DATE=`date +%d-%m-%y_%H-%M-%S`
                    sudo gzip -S "_$DATE.gz" $1
            fi

    }

    go_directory () {
            if [ -d "/var/log/apache2" ]
            then
                    if [ -f  "$1" ]
                    then
                            compress $1
                    fi
            fi
    }

    go_directory "/var/log/apache2/access.log"
    go_directory "/var/log/apache2/error.log"
    go_directory "/var/log/apache2/other_vhosts_access.log"

sudo chmod 764 apache2_log_compress.bash

Step 3: Setting a crontab

              crontab -e
            
              # runs per 1 minute.
              * 1 * * * /home/phyex/apache2_log_compress.bash 
              
              crontab -l 

About

Storing Apache2 Logs

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors