How to install Matomo web analytics platform on Ubuntu Server 20.04

March 30, 2022 0 Comments

Matomo logo
Photo: Matomo

If you manage websites, you know how important data analysis can be. You need to be aware of things like visitors, search engines and used keywords, spoken language, page likes, downloaded files and much more. That data can be an important part of growing and optimizing your site and the content you provide.

Views: Recruitment Kit: JavaScript Developer (TekriPublic Premium)

One tool for this is the open source Matomo (formerly Puik). Not only does Matomo keep you informed, it also works with Google AdWords, Facebook Ads, Yahoo and features a cost-per-click analysis, search marketing and a tracking and reporting API.

If this sounds like something that could benefit you and / or your company, let’s install it.

What you will need

I’m going to show Ubuntu Server 20.04, so you’ll need a running example of that platform, as well as a user account that has a pseudo feature.

Ready? Let’s do it.

How to install dependencies

The first thing we will do is install the necessary dependencies. Log in to your Ubuntu instance and install those packages with the command:

sudo apt-get install apache2 mariadb-server php libapache2-mod-php php-cli php-fpm php-fpm php-json php-json php-common php-mysql php-zip php-gd php-mbstring php-curl php-xml php-pear php-bcmath curl unzip -y

Once that installation is complete, you are ready to take care of the database.

How to create a database

Before we create the database, let’s start and enable MariadB:

sudo systemctl enable --now mariadb

Next, we need to protect MariadB. Order:

sudo secure_mysql_installation

Create a new password for the admin user and then answer ‘y’ for the remaining questions.

Log in to the MariadB console with:

sudo mysql

Create a database with:

CREATE DATABASE matomodb;

Create a new user with:

MariaDB [(none)]> CREATE USER 'matomo'@'localhost' IDENTIFIED BY 'PASSWORD';

Where PASSWORD is a strong / unique password.

Provide the user with the necessary facilities:

GRANT ALL ON matomodb.* TO 'matomo'@'localhost' WITH GRANT OPTION;

Flash all features and exit Database Console:

FLUSH PRIVILEGES;

exit

How to download and unpack Matomo

Download the latest version of Matomo with the command:

wget http://builds.matomo.org/matomo-latest.zip

Unpack the file with:

unzip matomo-latest.zip

Navigate to the newly created directory in the Apache document route:

sudo mv matomo /var/www/html/

Change permissions and ownership with:

sudo chown -R www-data:www-data /var/www/html/matomo

sudo chmod -R 755 /var/www/html/matomo

How to configure Apache

We now move on to the Apache configuration. Create a new .conf file with:

sudo nano /etc/apache2/sites-available/matomo.conf

In that file, paste the following (change as needed):

<VirtualHost *:80>

ServerAdmin [email protected]

ServerName matomo.example.com

DocumentRoot /var/www/html/matomo/

<Directory /var/www/html/matomo>

DirectoryIndex index.php

Options FollowSymLinks

AllowOverride All

Require all granted

</Directory>

<Files "console">

Options None

Require all denied

</Files>

<Directory /var/www/html/matomo/misc/user>

Options None

Require all granted

</Directory>

<Directory /var/www/html/matomo/misc>

Options None

Require all denied

</Directory>

<Directory /var/www/html/matomo/vendor>

Options None

Require all denied

</Directory>

ErrorLog ${APACHE_LOG_DIR}/matomo_error.log

CustomLog ${APACHE_LOG_DIR}/matomo_access.log combined

</VirtualHost>

Save and close the file.

Enable the site with:

sudo a2ensite matomo.conf\

Enable rewrite module with:

sudo a2enmod rewrite

Restart Apache with:

sudo systemctl restart apache2

How to finish the installation

Open a web browser and point it to http: // SERVER / matomo. You will be greeted with the Matomo Installation Wizard (Figure A)

Figure A

The Matomo Installation Wizard is easy to complete.
The Matomo Installation Wizard is easy to complete.

Click Next and the system check will be complete. Scroll down and click Next. In the resulting window (Figure B), Fill in the required information for the database. The login is matomo, the database name is matomodb, and the password is what you set on the MariaDB console. When finished, click on NEXT.

Figure B

Setting Database Parameters for Matomo.
Setting Database Parameters for Matomo.

Once the tables are created, click Next and then you will be asked to create a super user to act as a site administrator (Figure C)

Figure C

Creating a super user for the purpose of Matomo administration.
Creating a super user for the purpose of Matomo administration.

Click Next and in the next window (Figure D), You will be asked to set up a website for analysis.

Figure D

Your first site is being set up for analysis by Matomo.
Your first site is being set up for analysis by Matomo.

Click Next and then you will be asked to add the required JavaScript tracking code to your website. Closing the web pages you want to analyze You must add the script before tagging. The wizard’s tracking code page gives you lots of instructions on how to do this. The process will vary depending on how your websites were created and who hosts the sites

Before you click Next, be sure to click these instructions email (Figure e) So when you start adding tracking code to pages you have a reference copy.

Figure e

The tracking code guidelines are quite clear but will vary depending on how your sites were created.
The tracking code guidelines are quite clear but will vary depending on how your sites were created.

Click Next, and then click Continue to Matamo to reach the actual site, where you will be asked to log in with the admin account you created. You will then be presented with further instructions on how to add tracking code to your sites.

And that’s all there is to installing the Matomo web analytics platform. Once this platform is up and running, you’ll probably spend more time adding tracking code to sites than installing the platform. But if the data is important to you and your business, the effort will pay off.

Subscribe to TechRepublic How to do tech work on youtube From Jack Wallen to Business Professionals for all the latest technology advice.

Leave a Reply

Your email address will not be published.