How to Install Matomo Analytics on CentOS 7

Using a Different System?

  • How to Install Matomo Analytics on Ubuntu 16.04

  • How to Install Matomo Analytics on Debian 9

  • How to Install Matomo Analytics on Fedora 28

  • How to Install Matomo Analytics on FreeBSD 11

Are we missing a guide for your target system? Request one, or submit your own!


Matomo (formerly Piwik) is an open source analytics platform, an open alternative to Google Analytics. Matomo source is hosted on GitHub. It is a fully featured PHP/MySQL software program that you download and install on your own webserver. In this guide, we will install Matomo on a fresh CentOS 7 Vultr server instance.

Requirements

  • Nginx.
  • PHP version 5.5.9 or greater.
  • MySQL version 5.5 or greater, or MariaDB.
  • PHP extensions pdo and pdo_mysql, or the mysqli extension.

Before you begin

Check the CentOS version.

cat /etc/centos-release# CentOS Linux release 7.5.1804 (Core)

Create a new non-root user account with sudo access and switch to it.

useradd -c "John Doe" johndoe && passwd johndoeusermod -aG wheel johndoesu - johndoe

NOTE: Replace johndoe with your username.

Set up the timezone.

timedatectl list-timezonessudo timedatectl set-timezone 'Region/City'

Ensure that your system is up-to-date.

sudo yum update -y

Install needed packages to finish this tutorial.

sudo yum install -y wget curl vim zip unzip bash-completion

Disable SELinux and Firewall.

sudo setenforce 0sudo systemctl stop firewalldsudo systemctl disable firewalld

Install PHP and required PHP extensions

Setup the Webtatic YUM repo.

sudo rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

Install PHP and required PHP extensions.

sudo yum install -y php72w php72w-cli php72w-fpm php72w-common php72w-curl php72w-gd php72w-mysql php72w-xml php72w-mbstring

Check the PHP version.

php --version

Start and enable php-fpm.

sudo systemctl start php-fpm.servicesudo systemctl enable php-fpm.service

Install MariaDB

Install the MariaDB database server.

sudo vim /etc/yum.repos.d/MariaDB.repo# Copy/paste this to the /etc/yum.repos.d/MariaDB.repo file[mariadb]name = MariaDBbaseurl = https://yum.mariadb.org/10.2/centos7-amd64gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDBgpgcheck=1sudo yum install -y MariaDB-server MariaDB-client

Check the version.

mysql --version

Start and enable MariaDB.

sudo systemctl start mariadb.servicesudo systemctl enable mariadb.service

Run the mysql_secure_installation script to improve the security of your MariaDB installation.

sudo mysql_secure_installation

Log in to MariaDB as the root user.

mysql -u root -p# Enter password:

Create a new MariaDB database and user, and remember the credentials.

CREATE DATABASE dbname;GRANT ALL ON dbname.* TO 'username' IDENTIFIED BY 'password';FLUSH PRIVILEGES;EXIT;

Install and configure Nginx

Install Nginx.

sudo yum install -y nginx

Check the version.

sudo nginx -v

Start and enable Nginx.

sudo systemctl start nginx.servicesudo systemctl enable nginx.service

Configure Nginx. Run sudo vim /etc/nginx/conf.d/matomo.conf and populate the file with the following configuration.

server {    listen 80;    server_name stats.example.com;    root /var/www/matomo;    location / {        try_files $uri /index.php$is_args$args;    }    location ~ /.php$ {        try_files $uri =404;        include fastcgi_params;        fastcgi_pass 127.0.0.1:9000;        fastcgi_index index.php;        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;    }}

Test the configuration.

sudo nginx -t

Reload Nginx.

sudo systemctl reload nginx.service

Install Matomo

Create a document root directory.

sudo mkdir -p /var/www/matomo

Change ownership of the /var/www/matomo directory to johndoe.

sudo chown -R johndoe:johndoe /var/www/matomo

Download the latest release of Matomo.

cd /var/www/matomowget https://builds.piwik.org/piwik.zip && unzip piwik.ziprm piwik.zipmv piwik/* .rmdir piwik

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

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

Run sudo vim /etc/php-fpm.d/www.conf and set the user and group to nginx. Initially, they will be set to apache.

sudo vim /etc/php-fpm.d/www.conf# user = nginx# group = nginx

Restart php-fpm.

sudo systemctl restart php-fpm.service

Open your web browser and navigate to the URL to which you have uploaded Matomo. You will see the “Matomo Installation Welcome Screen”. If there are any problems, Matomo will identify them and offer a solution. Follow the instructions on the screen to finish the Matomo installation.

Want to contribute?

You could earn up to $300 by adding new articles

Submit your article
Suggest an update
Request an article

No comments

Powered by Blogger.