How to install Matomo (Piwik) Web Analytics Tool on Ubuntu 18.04 / Ubuntu 16.04

(: September 26, 2018)

Matamo (formerly Piwik) is a free and open source web analytics application developed in PHP to be the ultimate alternative to Google Analytics, with full control over your data. Matomo can be used for a site with a few visits per day or websites that receive many millions of visits per day to track Key Performance Indicators such as visits, goal conversion rates, downloads, keywords, and many more.

My previous related article was How to Install Fathom website analytics tool on Ubuntu / CentOS / Arch Linux

Matamo gives you a detailed user-centric insight on website actions, both for the direct visits to the website or access through a mobile application. You can extend and customize the application using its API’s and detailed user documentation. Install Matamo today and get to learn about your users’ behavior – where they come from, what they are doing and where they are going.{text-align:left} img{margin:0 auto 0 0}

See a full list of Matamo Dashboards

Install Matomo (Piwik) Web Analytics Tool on Ubuntu 18.04 / Ubuntu 16.04

The installation of Matomo ( formerly Piwik) on Ubuntu 18.04 / Ubuntu 16.04 is covered in this section. The process is straightforward and should be easy to follow.

To run Matomo (Piwik) your host server need to have a couple of things:

  • A web server such as Apache, Nginx, IIS, etc.
  • PHP version 5.5.9 or greater
  • MySQL version 5.5 or greater, or MariaDB
  • PHP extension pdo and pdo_mysql, or the mysqli extension.

Step 1: Install PHP 7 with required Extensions

Run below commands to install PHP 7 on your Ubuntu 18.04 / Ubuntu 16.04

sudo apt-get install php php-fpm php-curl php-gd php-cli php-mysql php-xml php-mbstring

Step 2: Install MySQL / MariaDB

As mentioned earlier, Matomo needs a database server, which can be MySQL or MariaDB. In this guide, we will install MariaDB using the guide below

Install MariaDB 10.x on Ubuntu 18.04 and CentOS 7

After installing a database server, proceed to create a user used by Matomo

Login to MySQL shell as root user

$ mysql -u root -p

Create a database and user with access privileges

GRANT ALL PRIVILEGES ON matomo.* TO 'matomo'@'localhost' IDENTIFIED BY "StrongPassword";

Step 2: Download Matomo / Piwik

Download the latest release of Matomo/Piwik using wget


Uncompress the package


Move piwik directory to /srv/

sudo mv piwik /srv/matomo/

Step 2: Install Nginx and configure Nginx

Download and install nginx

sudo apt-get install nginx

Create nginx configuration file for Matomo

sudo vim /etc/nginx/conf.d/matomo.conf

Add the following contents:

server {
    listen 80;
    root /srv/matomo;
    index  index.php index.html;
    access_log  /var/log/nginx/matomo_access.log;
    error_log   /var/log/nginx/matomo_error.log;

    client_max_body_size 100M;

    location / {
        try_files $uri /index.php?$query_string;

    location ~ .php$ {
    include /etc/nginx/fastcgi_params;
    fastcgi_pass             unix:/var/run/php/php7.2-fpm.sock;
    fastcgi_param            SCRIPT_FILENAME $document_root$fastcgi_script_name;

Change server_name and fastcgi_pass  values to match your correct settings.

Change Matomo directory ownership

sudo chown -R www-data:www-data /srv/matomo/

Start nginx and ensure it is set to start on boot

sudo systemctl restart nginx
sudo systemctl enable nginx

Step 3: Setup Matomo / Piwik

Access Setup web page by opening the link on your browser. You should be greeted with a welcome page. Click “Next”

Ensure all system checks are passed, then click the “Next” button

You should get to the Database Setup page. Use database credentials configured earlier

  • Database Server :
  • Login: matomo
  • Password: <StrongPassword>
  • Database Name: matomo
  • Adapter: PDO/MYSQL

Creation of the Tables should return a success.

Next, you have to create a Super User. Provide username, password and email address.

Setup a Website by providing:

  • Website name
  • Website URL
  • Website time zone
  • Enable/Disable Ecommerce

Copy and save generated JavaScript Tracking Code. A login page should appear, provide username and password to get in.

If you want to do more than track page views, please check out the Matomo Javascript Tracking documentation for the list of available functions. Using these functions you can track goals, custom variables, e-commerce orders, abandoned carts and more.{text-align:left} img{margin:0 auto 0 0}