CMS

Steps to Install Matomo on CentOS 7 Nginx

In this article, we will learn how to install Matomo on CentOS 7 Nginx.

Matomo, formerly Piwik, is a free and open source web analytics application developed by a team of international developers, that runs on a PHP/MySQL webserver. It tracks online visits to one or more websites and displays reports on these visits for analysis.

Why Matomo

Analytics data is yours to own. Your Matomo Analytics data is 100% yours to own, with no external parties looking in.

Unlike Google Analytics which uses your data to serve its advertising platform, Matomo users can safely use analytics without worrying about data being used for marketing or any other purposes.

Prerequisites:

Before you get started, ensure that you have the following:

  • VPS or dedicated server.
  • An operating system running CentOS 7
  • Access to your web server (via shell or FTP)

1. Initial steps

Keep your server up-to-date:

# yum update -y

2. Install MariaDB 10.4 and create database for Matomo

Create the MariaDB.repo file in you favourite editor:

# vi /etc/yum.repos.d/MariaDB.repo

And add following lines:

# MariaDB 10.4 CentOS repository list
# http://downloads.mariadb.org/mariadb/repositories/
[mariadb]

name = MariaDB
baseurl = http://yum.mariadb.org/10.4/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1

Now, start the installation of the MariaDB 10.4

# yum install MariaDB-client MariaDB-server

After it’s finished, start MariaDB:

# systemctl start mariadb.service

# systemctl enable mariadb.service

Secure the MySQL

# mysql_secure_installation

2. Install Nginx

Add EPEL(Extra Packages for Enterprise Linux) repository:

# yum install epel-release

Now, install NGINX using following command:

# yum install nginx

Start and enable Nginx service

# systemctl start nginx

# systemctl enable nginx

Configure Nginx for Matomo

# vi /etc/nginx/conf.d/matomo.conf

Add following configuration lines:

server {

listen [::]:80;
listen 80;

server_name example.com;
root /var/www/matomo/;
index index.php;

location ~ ^/(index|matomo|piwik|js/index).php {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
try_files $fastcgi_script_name =404;
set $path_info $fastcgi_path_info;
fastcgi_param PATH_INFO $path_info;
fastcgi_index index.php;
include fastcgi.conf;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param HTTP_PROXY “”;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
}

location = /plugins/HeatmapSessionRecording/configs.php {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
try_files $fastcgi_script_name =404;
set $path_info $fastcgi_path_info;
fastcgi_param PATH_INFO $path_info;
fastcgi_index index.php;
include fastcgi.conf;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param HTTP_PROXY “”;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
}

location ~* ^.+\.php$ {
deny all;
return 403;
}

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

location ~ /(config|tmp|core|lang) {
deny all;
return 403;
}

location ~ \.(gif|ico|jpg|png|svg|js|css|htm|html|mp3|mp4|wav|ogg|avi|ttf|eot|woff|woff2|json)$ {
allow all;
}

location ~ /(libs|vendor|plugins|misc/user) {
deny all;
return 403;
}

}

Do not worry about SSL redirection for now. We will install Let’s Encrypt using Certbot later in this article. Certbot will add SSL redirection and certificate location automatically during the obtaining of the certificate.

Test the configuration

# nginx -t

If test get successfully, restart Nginx service. If test gets fail, check the error and modify the configuration file as we the requirements.

# systemctl restart nginx

3. Install PHP with PHP-FPM for Nginx

Install Remi repository:

# rpm -Uvh http://rpms.remirepo.net/enterprise/remi-release-7.rpm

Enable PHP version:

# yum-config-manager –enable remi-php73

Now, install PHP 7.3 along with required PHP modules:

# yum -y install php php-fpm php-common php-mysqlnd php-gd  php-json php-libxml php-mbstring php-xml php-curl php-fileinfo  php-mcrypt php-memcached php-imagick

Open the php-fpm configution file:

# vi /etc/php-fpm.d/www.conf

Look for user and group, change the parameter to nginx from apache.

user = nginx

group = nginx

Find listen parameter and change it like:

listen = /var/run/php-fpm/php-fpm.sock

Find lines that set the listen.owner and listen.group and uncomment them. Set to nginx:

listen.owner = nginx

listen.group = nginx

After you done configurion, save and exit.

Now, start and enable PHP processor:

# systemctl start php-fpm

# systemctl enable php-fpm

4. Install Let’s Encrypt using Certbot

Install certbot-nginx package:

# yum install certbot-nginx -y

Obtaining a Certificate

# certbot –nginx -d yoursite.com -d www.yousite.com

5. Install Matomo Analytics

Navigate to /var/www directory

# cd /var/www/

Download the latest release Matomo using wget command and unzip it

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

Remove downloaded matomo.zip file

# rm -rf matomo.zip

Change the ownership of the /var/www/matomo directory to nginx user

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

6. Complete the Matomo Analytics

Open your website in browser and follow the Matomo web installation wizard.

Time to get started with the point-and-click installation! Click Next »

Install Matomo HostnExtra

 

We have successfully learnt how to install Matomo on CentOS 7 Nginx.

 

[Need assistance to fix this error or install tools? We’ll help you.]

Related Articles