How to Install Matomo on Ubuntu 16.04

how to install matomo on ubuntu 16.04

Today we are going to show you how to install Matomo on  Ubuntu 16.04. Matomo (formerly known as Piwik) is a free and popular analytics platform currently used by individuals, companies and governments all over the world. To install Matomo on Ubuntu 16.04, carefully follow the steps below and you should have Matomo installed on your Ubuntu 16.04 server in less then 10 minutes. Let’s get started with the installation.


  • PHP >= 5.59 (PHP 7.0 or above is recommended), with the following PHP extensions enabled: XML (Expat), curl, GD Graphics Library version 2.0.x+ and mbstring.
  • Apache Web Server >= 2.0 compiled with mod_rewrite module, or Nginx
  • MySQL 5.5 or later is recommended, or MariaDB installed on your Linux virtual server.

installing matomo on ubuntu 16.04

Login via SSH and update the system

To begin, log in to your Ubuntu 16.04 VPS via SSH as user root

ssh root@IP_Address -p Port_number

Make sure that all OS packages are up to date by running the following command-line commands:

apt-get update
apt-get upgrade

You should always keep your system updated for security reasons.

Create a MySQL database for Matomo

Log into MySQL with the root account:

# mysql -u root -p

Now we will create a MySQL database for Matomo using the following query:

mysql> CREATE DATABASE matomo;

Then execute the following query to add a separate user for Matomo that will interact with the database:

mysql> GRANT ALL PRIVILEGES ON matomo.* to 'matomo'@'localhost' IDENTIFIED BY '5tr0ng_Pa55w0rd';

Execute the following command to apply the privileges we set:


Now we can exit the MySQL session:

mysql> quit

Install and Configure Matomo on Ubuntu 16.04

First make sure the following packages are installed as they are needed by Matomo:

# sudo apt-get install libapache2-mod-php7.0 php7.0 php7.0-cli php7.0-common php7.0-curl php7.0-gd php7.0-mbstring php7.0-mysql php7.0-xml

Download the latest release Matomo (Piwik) and extrat it to the /var/www/matomo directory on the server:

cd /opt
wget -O
unzip -d /var/www/

This will create a new directory named ‘matomo’ containing the necessary files and directories.
Change the ownership of the matomo directory

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

Configure Apache to serve Matomo

Now we will have to setup the Apache configuration so it can serve the Matomo directory, add the following contents below to the /etc/apache2/sites-available/matomo.conf file with nano or your favorite editor:

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

Add the following lines:

<VirtualHost *:80>
DocumentRoot /var/www/matomo

Alias /matomo “/var/www/matomo/”
<Directory /var/www/matomo/>
Options +FollowSymlinks
AllowOverride All


ErrorLog /var/log/apache2/matomo-error_log
CustomLog /var/log/apache2/matomo-access_log common

Enable the following Apache modules:

# sudo a2enmod rewrite
# sudo a2enmod headers
# sudo a2enmod env
# sudo a2enmod dir
# sudo a2enmod mime

Enable the Apache ownCloud configuration:

# sudo a2ensite matomo.conf

Remove the default Apache configuration file:

rm /etc/apache2/sites-enabled/000-default.conf

Now restart the Apache web server:

# sudo systemctl restart apache2

Open your web browser and type in the following URL to access the Matomo web interface:

From here you can finish the setup by following the steps below:

Need a fast and easy fix?
✔ Unlimited Managed Support
✔ Supports Your Software
✔ 2 CPU Cores
✔ 2 GB RAM
✔ 50 GB PCIe4 NVMe Disk
✔ 1854 GeekBench Score
✔ Unmetered Data Transfer

Now just $43 .99

  • Matomo will check to make sure that your server meets the Matomo requirements. If everything is OK, click Next
  • Enter localhost or as database server, then enter a database username and password, database name, and once you have filled in the form, click Next
  • You should receive a message: ‘Tables created with success!’. Click on the Next button once again
  • Enter a username, password and email address for the administrator user account
  • On the next page, set up the Website name and URL you want to track.

That’s it, now you should have successfully installed Matomo on your server. You need to add the JavaScript tracking code on every page of your website before the closing tag so you can track and analyze the websites. You can now log in to the Matomo administration back-end and add more websites, check the stats etc.

Since millions of websites today are powered by WordPress, there is a very useful plugin which will help you to add all the website stats at your Matomo dashboard. You can get the plugin at There are much more ways to integrate Matomo with other popular applications. You can check the list of all available Matomo plugins and extensions here.

If your website is a medium or high-traffic website, it is a good idea to set up a cron job so that Matomo calculates the reports periodically. Create a new file matomo-archive in the /etc/cron.d/ directory:

nano /etc/cron.d/matomo-archive

add the following line:

MAILTO=”” 5 * * * * www-data /usr/bin/php /var/www/matomo/console core:archive –url= > /var/log/apache2/matomo-archive.log

install matomo on ubuntu 16.04Of course, you don’t have to install and configure Matomo on Ubuntu 16.04, if you use one of our Ubuntu Hosting solutions, in which case you can simply ask our expert Linux admins to install and configure Matomo on Ubuntu 16.04 for you. They are available 24×7 and will take care of your request immediately.

PS. If you liked this post on how to install and configure Matomo on a Ubuntu 16.04 VPS, please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.

2 thoughts on “How to Install Matomo on Ubuntu 16.04”

Leave a Comment