---
title: Setting up web analytics with Matomo on a Scaleway Instance
description: This page shows you how to install and configure Matomo web analytics on a Scaleway Instance running Ubuntu Focal Fossa (20.04)
products:
  - instances
tags: Matomo Ubuntu Focal-Fossa LEMP-Stack analytics
dates:
  validation: 2024-09-16
  posted: 2019-07-24
  validation_frequency: 24
hero: assets/scaleway-matomo.webp
difficulty: beginner
usecase:
  - application-hosting
ecosystem:
  - third-party
---
import image from './assets/scaleway-matomo-setup1.webp'
import image2 from './assets/scaleway-matomo-setup2.webp'
import image3 from './assets/scaleway-matomo-login.webp'
import image4 from './assets/scaleway-matomo-dashboard.webp'

import Requirements from '@macros/iam/requirements.mdx'


[Matomo](https://matomo.org/) (former: Piwik) is an open-source web analytics platform designed to evaluate the visitor's behavior for one or multiple websites.

The tool is written in PHP and stores its data in a MySQL/MariaDB database.

<Requirements />

- A Scaleway account logged into the [console](https://console.scaleway.com)
- [Owner](/iam/concepts/#owner) status or [IAM permissions](/iam/concepts/#permission) allowing you to perform actions in the intended Organization
- An [SSH key](/organizations-and-projects/how-to/create-ssh-key/)
- An [Instance](/instances/how-to/create-an-instance/) running on Ubuntu Focal Fossa (20.04) or later
- `sudo` privileges or access to the root user

## Installing the LEMP-stack

Matomo requires a web server, such as [Nginx](http://nginx.org/), to operate. Ensure that a functional [LEMP stack](/tutorials/installation-lemp-ubuntu-bionic/) is installed on your Instance before running Matomo.

1. Update the APT package cache and upgrade the packets already installed on the Instance.
    ```
    apt update && apt -y upgrade
    ```
2. Install the required software via `apt`.
    ```
    apt install -y ufw nginx mariadb-server php-fpm php-mysql php-curl php-gd php-cli php-xml php-mbstring software-properties-common
    ```
3. [Secure the MariaDB server](/tutorials/mariadb-ubuntu-bionic/#securing-mariadb) by executing the following command.
    ```
    mysql_secure_installation
    ```

    When asked for the current MySQL root password, press **Enter** as no password is set by default.
4. Install [Certbot](https://certbot.eff.org/) to manage the TLS/SSL certificate.
    ```
    apt install -y python3-certbot-nginx
    ```

## Downloading Matomo

1. Enter the directory `/var/www/html`.
    ```
    cd /var/www/html
    ```
2. Download the latest release of Matomo.
    ```
    wget https://builds.matomo.org/matomo-latest.tar.gz
    ```
3. Unpack Matomo.
    ```
    tar xfz matomo-latest.tar.gz
    ```
4. Set the ownership of the Matomo files to the `www-data` user.
    ```
    chown -R www-data:www-data matomo
    ```

## Configuring the Nginx web server

<Message type="note">
  When following the next steps, replace `matomo.example.com` with your domain name.
</Message>

1. Create a Nginx configuration file and open it in a text editor.
    ```
    nano /etc/nginx/sites-available/matomo.example.com
    ```
2. Copy the following content into the configuration file.
    ```
    server {
            listen 80;
            root /var/www/html/matomo;
            index index.php index.html index.htm;
            server_name matomo.example.com;

            location / {
                    try_files $uri $uri/ =404;
            }

            location ~ \.php$ {
                    include snippets/fastcgi-php.conf;
                    fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
            }

            location ~ /\.ht {
                    deny all;
            }
    }
    ```
3. Enable the newly created site by creating a symlink.
    ```
    ln -s /etc/nginx/sites-available/matomo.example.com /etc/nginx/sites-enabled/
    ```
4. Check the Nginx configuration file for possible errors.
    ```
    nginx -t
    ```
5. Reload Nginx to activate the new configuration.
    ```
    service nginx reload
    ```
6. [Run Certbot](/tutorials/installation-lemp-ubuntu-bionic/#configuring-ssl-with-lets-encrypt) with the `--nginx` flag to request a Let's Encrypt TLS/SSL certificate for the newly created server block.
    ```
    certbot --nginx
    ```

## Creating a MySQL database for Matomo

1. Log into the MySQL shell with the `root` user.
    ```
    mysql -u root -p
    ```

    <Message type="important">
      The password of the MySQL root user is the one configured during the secure installation of MySQL.
    </Message>
2. Run the following commands from the MySQL shell to create the database for Matomo.
    ```
    CREATE DATABASE matomodb;
    GRANT ALL ON matomodb.* TO matomo@localhost IDENTIFIED BY 'SECURE-DATABASE-PASSWORD';
    FLUSH PRIVILEGES;
    quit;
    ```

## Running the Matomo web installer

1. Open a web browser and go to `https://matomo.example.com/`. The web installer displays. Click **Next** to go to the second step:
    <Lightbox image={image} alt="" />

    Matomo launches some automatic checks if all pre-requirements are fulfilled.
2. Click **Next** to continue with the installation, if all prerequisites are met.
3. Proceed with the database configuration.

    Enter the following information for your database:
      - **Database Server**: `127.0.0.1`
      - **Login**: The Matomo database user (`matomo`)
      - **Password**: The Matomo database password (`SECURE-DATABASE-PASSWORD`)
      - **Database Name**: The Matomo database name (`matomodb`)
      - **Table Prefix**: A prefix for the Matomo tables, you can keep the default values (`matomo_`)
      - **Adapter**: Leave the default value (`PDO\MYSQL`)

    Click **Next** to proceed with the installation.

    Matomo verifies the MySQL/MariaDB credentials. If all is in order, the database structure is created automatically, and a success message displays.
4. Click **Next** to continue with the installation:
    <Lightbox image={image2} alt="" />
5. Configure a super-user (or admin user) for Matomo. This will be the main user who can configure all settings and add users and sites:

    Enter the following credentials for your user:
      - **Super user login**: Choose an identifier for the user
      - **Password**: Choose a secure password for the user
      - **Password (repeat)**: Repeat the secure password for the user
      - **Email**: Link an email address to the super-user account
      - Tick the first box to receive notifications about Matomo updates by email (optional)
      - Tick the second box if you want to receive commercial information from Matomo by email (optional)

    Click **Next** to create the super-user account and proceed with the installation.
6. Set up the first website you want Matomo to track and analyze.

    Enter the following information for your website:
      - **Website name**: Enter the name of the website
      - **Website URL**: Enter the website URL
      - **Website time zone**: Set the time zone for the website. This is important so Maotomo can track the visitors with the correct time of their visit
      - **E-commerce**: Enable specific tracking methods if the website is an e-commerce site

    Click **Next** to validate the form and to continue with the installation.

    <Message type="important">
      Additional websites can be configured once the initial setup has been completed.
    </Message>

    A tracking code appears. Ensure that the tracking code is on every page of your website. It is recommended to put it in the header of the website, immediately before the closing `</head>` tag.
7. Copy the displayed tracking code and put it into your website header. The tracking code looks like the following example:
    ```js
    <!-- Matomo -->
    <script type="text/javascript">
      var _paq = window._paq || [];
      /* tracker methods like "setCustomDimension" should be called before "trackPageView" */
      _paq.push(['trackPageView']);
      _paq.push(['enableLinkTracking']);
      (function() {
        var u="//matomo.scw-site.ml/";
        _paq.push(['setTrackerUrl', u+'matomo.php']);
        _paq.push(['setSiteId', '1']);
        var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
        g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
      })();
    </script>
    <!-- End Matomo Code -->
    ```

    Click **Next** once you have copied the code to continue with the installation.

The installation completes. It is possible to anonymize the data tracked by Matomo. This is recommended to comply with data protection regulations.

## Logging in to Matomo

Once the installation is completed, the login screen displays:

<Lightbox image={image3} alt="" />

Enter the **super-user** login and the password set in the previous step.

The **Matomo Dashboard** displays. If the tracking code is added to the website, the application begins to track users and generates usage statistics over time:

<Lightbox image={image4} alt="" />

Matomo is now installed, counting visitors and analyzing their behavior. For more information about the integration of Matomo on different [Content Management Systems (CMS)](https://matomo.org/docs/integration/) and [advanced configuration](https://matomo.org/docs/include-piwik-in-your-project/) of the tool, refer to the [official documentation](https://matomo.org/docs/#configuration).