How to Install Matomo Web Analytics Platform on Ubuntu Server 20.04
If you are a website administrator, you know how important data analysis can be. You may need to keep track of things like visitors, search engines and keywords used, languages spoken, pages liked, files downloaded and more. This data can play an important role in growing and optimizing your sites and the content you provide.
TO SEE: Recruitment Kit: JavaScript Developer (TechRepublic Premium)
A tool for this is the open-source Matomo (formerly Piwik). Not only can Matomo keep you informed, but it also works with Google AdWords, Facebook Ads, Yahoo, and offers cost-per-click analysis, search marketing, and tracking and reporting API.
If that sounds like something you and/or your business could benefit from, let’s install it.
What you will need
I’ll be demoing on Ubuntu Server 20.04, so you’ll need a running instance of that platform, and a user account with sudo privileges.
Ready? Let’s do this.
How to install dependencies
The first thing we are going to do is install the necessary dependencies. Connect to your Ubuntu instance and install these 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 this installation is complete, you are ready to take care of the database.
How to create the database
Before creating the database, let’s start and activate MariaDB with:
sudo systemctl enable --now mariadb
Next, we need to secure MariaDB. Issue the command:
sudo secure_mysql_installation
Create a new password for the admin user, then answer “y” for the remaining questions.
Connect to the MariaDB console with:
sudo mysql
Create the 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.
Grant the necessary privileges to the user with:
GRANT ALL ON matomodb.* TO 'matomo'@'localhost' WITH GRANT OPTION;
Dump all privileges and exit the database console with:
FLUSH PRIVILEGES;
exit
How to download and unzip Matomo
Download the latest version of Matomo with the command:
wget http://builds.matomo.org/matomo-latest.zip
Unzip the file with:
unzip matomo-latest.zip
Move the newly created directory into the Apache document root with:
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
Now let’s get to configuring Apache. Create a new .conf file with:
sudo nano /etc/apache2/sites-available/matomo.conf
In this file, paste the following (modifying it if necessary):
ServerAdmin admin@example.com
ServerName matomo.example.com
DocumentRoot /var/www/html/matomo/
DirectoryIndex index.php
Options FollowSymLinks
AllowOverride All
Require all granted
Options None
Require all denied
Options None
Require all granted
Options None
Require all denied
Options None
Require all denied
ErrorLog ${APACHE_LOG_DIR}/matomo_error.log
CustomLog ${APACHE_LOG_DIR}/matomo_access.log combined
Save and close the file.
Activate the site with:
sudo a2ensite matomo.conf
Activate the rewrite module with:
sudo a2enmod rewrite
Restart Apache with:
sudo systemctl restart apache2
How to complete the installation
Open a web browser and point it to http://SERVER/matomo. You will be greeted by the Matomo Setup Wizard (Figure A).
Figure A

Click NEXT and the system check will complete. Scroll down and click NEXT. In the resulting window (Figure B), fill in the necessary information for the database. The connection is matomo, the database name is matomodb, and the password is the one you set in the MariaDB console. Click NEXT when finished.
Figure B

Once the tables are created, click Next and you will then be prompted to create a superuser to serve as the site administrator (Figure C).
Figure C

Click Next and in the next window (Figure D), you will be prompted to set up a website to crawl.
Figure D

Click Next and you will then be prompted to add the necessary JavaScript tracking code to your website. You will need to add the script before the closing tag on the web pages you want to analyze. The wizard’s tracking code page gives you plenty of instructions for doing this. The process will vary depending on how your websites were created and who is hosting the sites.
Before clicking NEXT, be sure to click EMAIL THESE INSTRUCTIONS (Figure E) so that you have a reference copy for when you actually start adding tracking code to pages.
Figure E

Click Next, then CONTINUE TO MATOMO to finally get to the real site, where you will be prompted to log in with the administrator account you created. You will then receive even more instructions on how to add the 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 will likely 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 make technology work on YouTube for all the latest tech tips for professionals from Jack Wallen.
Comments are closed.