How To Install Goaccess To Analyze Apache Linux Log
GoAccess has been developed to be a web-based real-time web log analyzer which has an interactive viewer that runs on a terminal on UNIX systems through the web browser.
By default, the results generated with this utility are through the terminal, it can produce a complete HTML report in real time, as well as JSON and CSV report.
Now we will see how to install GoAccess, and for this, we will use Ubuntu 17 Server.
Step 1: Update Linux
The first step is to update the operating system packages, and for this, we will execute the following commands:
sudo apt-get update -y sudo apt-get upgrade -y
Step 2: Install Dependencies
The GoAccess utility is written in C, which is why it will be necessary to install some dependencies required by GoAccess, for this, we can install them with the following command:
sudo apt-get -y install libncursesw5-dev gcc make libgeoip-dev libtokyocabinet-dev build-essential -y
Step 3: Install Apache Web Server
GoAccess is a tool focused on analyzing web server logs, so it is necessary to install Apache in the distribution and for installation, it can be installed with the following command:
sudo apt-get install apache2 -y
Once installed, we proceed to start the service and enable it at system startup by executing the following:
sudo systemctl start apache2 sudo systemctl enable apache2
Step 4: Install GoAccess on Linux
Once we complete the steps above it is time to install GoAccess which we can do in two ways.
The first alternative, which we will use in this tutorial, is through the official GoAccess resource, for this, firstly, we will download the latest version of GoAccess using the wget command in the following way:
Extract the downloaded file by executing:
sudo tar -xzvf goaccess-1.2.tar.gz
Now, we go to the directory to goaccess-1.2 and compile GoAccess by executing the following command:
cd goaccess-1.2 sudo ./configure --enable-utf8 --enable-geoip=legacy
Once this process is finished we will see the following:
Now we execute:
Finally, we install GoAccess running:
sudo make install
The second alternative to install GoAccess is through a repository, for this, it will be necessary to download the GoAccess repository using apt with the following command:
echo "deb http://deb.goaccess.io/ $(lsb_release -cs) main" | sudo tee -a /etc/apt/sources.list.d/goaccess.list wget -O - https://deb.goaccess.io/gnugpg.key | sudo apt-key add –
Then, we will update the repository using the following command:
sudo apt-get update -y
Finally, we install GoAccess by running:
sudo apt-get install goaccess -y
Step 5: Use GoAccess on Linux
The time has come to check the use of GoAccess and for this, first, we will access the Apache web server using the following syntax:
As we can see, access to Apache works correctly. After accessing the web server, Apache will be responsible for adding some registry entries in the access_log file by default.
Now it is possible to analyze the Apache web server log from the terminal by executing the following command:
sudo goaccess /var/log/apache2/access.log --log-format=COMBINED
There we find the Apache web server statistics in real time. Now, it is also possible to generate a report in HTML format by executing the following line:
sudo goaccess /var/log/apache2/access.log --log-format=COMBINED -a -o /var/www/html/report.html
Once this report is created, we can access it from our browser by executing the following:
There we can graphically view the statistics in real time Apache web server.
We can see how GoAccess is a simple but complete utility that allows us to have a centralized control over everything that happens in the Apache web server.