Feb 26, 20204 min read

How to install Matomo on Ubuntu 18.04

Matomo

Matomo is an open-source web analytics platform. It is a great alternative to Google Analytics. This platform offers you 100% control of yours and your users’ data.

You don’t need to install Matomo to see what it can do for you. Let’s take a quick tour around the demo site at demo.matomo.org.

Matomo dashboard
Dashboard

The open-source self-hosted Matomo can show the following reports:

  • Top keywords and search engines, referrals, social media.

  • Top pages URLs, page titles, user countries, providers, operating systems, browsers shares, screens resolutions, desktop vs. mobile.

  • Engagement (time on site, pages per visit, repeated visits).

  • Top campaigns, custom variables, top entry/exit pages, downloaded files, and many more.

  • Classified into four main analytics report categories – Visitors, Actions, Referrers, Goals/Ecommerce (30+ reports).

  • Statistics email reports.

  • Web server analytics logs.

  • Tools to comply with GDPR (such as cookie consent)

  • Install free or premium plugins to extend and expand the functionality of Matomo.

  • And more features.

You can check the Matomo features page, for the full list of features.

I’ve chosen to self-host my own Matomo for these benefits:

  • Full control of data. Data is only stored on your server, and you can choose which country the server is located in.

  • No data limits. You can hold as much data as your server can fit.

  • Fully customizable and extensible.

  • Firefox started blocking cross-site tracking cookies, including Google Analytics. By hosting the analytics software under your own domain name, your tracking cookies won’t be blocked.

Required services

  • The latest PHP 7.x release

  • MySQL 5.7+ for your database

  • Nginx Webserver

Create MySQL database

Install PHP and MySQL.

Connect to your MySQL database.

Create a database for Matomo. Replace matomo_db_name with your database name.

Create a user called "matomo". Replace strong-password with your strong secured password.

Grant this user matomo the permission to access your matomo_db_name database.

Grant this user matomo the FILE global privilege.

Exit MySQL.

Install Matomo

Install unzip.

Get the latest version of Matomo and unzip it.

Move matomo directory to /srv/.

Change the ownership of Matomo directory.

NGINX

Get NGINX.

Create NGINX configuration file.

Insert the following lines in the configuration file. Replace analytics.example.com with the domain you would like to use to access your Matomo installation.

Test your NGINX configuration, restart it and add it to boot services.

SSL certificate

Install Certbot.

With Certbot, you can generate a SSL certificate (thanks to LetsEncrypt) by running this command:

Configure Matomo

Go to your domain, here analytics.example.com. If everything is installed correctly, you should see the Matomo Installation Welcome Screen. Follow the steps.

System Check

Matomo will check your installation to make sure that your server meets the Matomo requirements. If everything is okay, you’ll see a long list like this:

Matomo check success
Check success

If there is a problem, Matomo will identify it and tell you how to solve it, as in this example:

Matomo check failed
Check failed

MySQL Database Set up

For the database setup, use the following credentials:

Matomo db setup
Database set up

Super User

Now you should create your super user. This user has the highest permissions. Insert your username, password and email. Do not lose those; it is the only way for you to log in to Matomo for the first time.

Matomo superuser setup
Super user set up

Setup Your First Website

Enter the name and URL of the first website you want to track. You can add more websites once the installation is complete.

Matomo website setup
Website set up

Install the JavaScript Tracking Tag

Matomo will generate a JavaScript tag for you. This code must appear on every page that you want Matomo to analyse. It's recommended that you paste this code immediately before your closing </head> tag.

Matomo javascript tag
Javascript tag

For Gatsby sites, you could use the gatsby-plugin-matomo.

Add this line to your gatsby.config file.

Congratulations

You have installed your self-hosted Matomo Web Analytics. Now you can perform a wide range of functions, including tracking goals and placing orders online.