Article

Table of Contents
Theme:
Was this article helpful?
Try Vultr Today with

$50 Free on Us!

Want to contribute?

You could earn up to $600 by adding new articles.

How to Install Matomo Analytics on FreeBSD 13.0

Author: Humphrey Mpairwe

Last Updated: Fri, Feb 11, 2022
BSD Server Apps

Matomo Analytics is an open-source self-hosted web analytics application that allows you to keep track of your website visitors. Formerly Piwik, Matomo Analytics is the open-source alternative to Google Analytics, offering similar tools and web monitoring tools.

In this article, you will learn how to install and configure Matomo Analytics on a FreeBSD 13.0 Vultr server instance.

Prerequisites

Step 1: Create the Matomo Analytics Database

Create a new Database.

CREATE DATABASE Matomo;

Create a new Database User with a Strong Password.

CREATE USER 'admin'@'localhost' IDENTIFIED WITH mysql_native_password BY ‘STRONG-PASSWORD';

Grant the user full permissions to the Matomo Database.

GRANT ALL PRIVILEGES ON matomo.* TO admin@localhost;

Refresh MySQL privileges. FLUSH PRIVILEGES;

Exit the MySQL console.

EXIT

Step 2: Install Necessary PHP Extensions

Matomo analytics is a PHP-based application, and so it requires a specific group of PHP extensions to run. Most importantly, php-session, php-json, php-pdo_mysql are required.

Install them using the following command:

# pkg install php74 php74-curl php74-gd php74-pdo-mysql php74-session php74-json php74-zlib php74-filter php74-xml php74-mbstring

Enable PHP-FPM.

# sysrc php_fpm_enable=yes

Start PHP-FPM.

# service php-fpm start

Step 3: Install Matomo Analytics

By default, Nginx points to /usr/local/www/ as the web root directory. You can change it to a more convenient directory. We’ll create a Matomo web files directory in /var/www in this article.

Create the /var/www/ directory.

# mkdir /var/www

Create the Matomo Analytics web files directory.

# mkdir /var/www/matomo

Grant Nginx read and write permissions to the directory.

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

Now, download the latest Matomo release file.

# wget https://builds.matomo.org/matomo.zip

Unzip the file.

# unzip matomo.zip

Move the extracted files to the Matomo directory.

# mv matomo/* /var/www/matomo/

Grant Nginx full permissions to the directory.

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

Then, set the correct file and directory permissions using the following commands:

# find /var/www/matomo/. -type f -exec chmod 644 {} ;
# find /var/www/matomo/. -type d -exec chmod 755 {} ;

Step 4: Configure Nginx

Create a new Nginx configuration file.

# touch /usr/local/etc/nginx/matomoanalytics.conf

Now, install Nano or your preferred text editor:

# pkg install nano

Open and edit the file.

# nano /usr/local/etc/nginx/matomoanalytics.conf

Paste the following contents:

server {

  listen 80;
  server_name analytics.example.com; 
  root /var/www/matomo;
  index index.php index.html index.htm;

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

  location ~ \.php$ {
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
    fastcgi_read_timeout 300;
    proxy_read_timeout 300;
  }

 }

Replace analytics.example.com with your actual domain name.

Save and close the file.

Then, edit the main Nginx configuration file.

# nano /usr/local/etc/nginx/nginx.conf

At the end of the file, add the following line within the http { } block to enable the Matomo configuration file.

include matomoanalytics.conf;

Save and close the file.

Now, test the Nginx configuration file for errors.

# nginx -t

If all is well, your output should be:

nginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok 
nginx:  configuration file /usr/local/etc/nginx/nginx.conf test is successful

Restart Nginx.

# service nginx restart

Step 5: Setup Matomo Analytics

Using a web browser, visit your domain name.

https://analytics.example.com

Click Next to start the Matomo installation wizard.

A system check will run to confirm installed components on your server. Then, click Next to proceed to the database setup page.

Matomo Analytics Database Setup Page

Enter the Username, Password, and Database name created on Step 1 of this article. Then, click Next to create the necessary tables.

Now, enter a Super User (administrator) username, password, and email that will be used to access the Matomo Analytics backend portal.

Click Next to set up a website to track with Matomo Analytics, copy the tracking code, then continue and log in to the backend portal to start tracking web visits.

Matomo Analytics Backend Dashboard

Conclusion

You have successfully installed and set up Matomo Analytics on FreeBSD 13.0. Depending on the number of websites you intend to monitor, consider scaling your server with reference to the recommended Matomo server requirements.

Want to contribute?

You could earn up to $600 by adding new articles.