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

Cpanel/Whm License $3/mo Plesk License $10/mo Cloudlinux License $5/mo

(: 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.

.td_uid_2_5d90650500098_rand.td-a-rec-img{text-align:left}.td_uid_2_5d90650500098_rand.td-a-rec-img 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

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

Step 2: Download Matomo / Piwik

Download the latest release of Matomo/Piwik using wget

wget https://builds.piwik.org/piwik.zip

Uncompress the package

unzip piwik.zip

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;
    server_name  stats.example.com www.stats.example.com;

    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 http://stats.example.com 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 : 127.0.0.1
  • 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.

.td_uid_4_5d906505002f3_rand.td-a-rec-img{text-align:left}.td_uid_4_5d906505002f3_rand.td-a-rec-img img{margin:0 auto 0 0}

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More