Skip to main content

Matomo on CentOS 7

Matomo or formerly known as Piwik, is an open source web analytics application. It rivals Google Analytics and includes even more features and allows you to brand your brand and send out custom daily, weekly, and monthly reports to your clients.

First let’s start by ensuring your system is up-to-date and has the needed repositories.

yum -y install epel-release
yum -y install https://centos7.iuscommunity.org/ius-release.rpm
yum clean all
yum -y update
reboot # if kernel updated

Install needed packages

yum -y install wget mariadb mariadb-server mysql httpd openssl mod_ssl php72u-json mod_php72u php72u-gd php72u-imap php72u-ldap php72u-odbc pear1u php72u-xml php72u-xmlrpc php72u-mbstring php72u-mysqlnd php72u-snmp php72u-soap php72u-tidy curl curl-devel mcrypt

Configure MySQL

systemctl restart mariadb.service   # Start MySQL service
mysql_secure_installation   # Set root password 
mysql -u root -p   # Enter root password

Add the database and user.

CREATE DATABASE IF NOT EXISTS matomodb DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
GRANT ALL PRIVILEGES ON matomodb.* TO 'matomouser'@'localhost' IDENTIFIED BY 'YourAwesomePassword' WITH GRANT OPTION;
FLUSH PRIVILEGES;
quit

Installing Matomo on CentOS 7.

cd /var/www
wget https://builds.matomo.org/piwik.zip

Unpack the Matomo archive to the document root directory on your server.

unzip piwik.zip -d /var/www/html/
mv /var/www/html/piwik/ /var/www/html/matomo/

Update owner on Matomo files and folders

chown -R apache:apache /var/www/html/matomo

Configure Apache
Create Apache virtual host for Matomo . First create ‘/etc/httpd/conf.d/vhosts.conf’ file

vim /etc/httpd/conf.d/vhosts.conf

IncludeOptional vhosts.d/*.conf

Create the virtual host.

mkdir /etc/httpd/vhosts.d/
vim /etc/httpd/vhosts.d/yourdomain.com.conf

Add the following to the new vhost config.

<VirtualHost YOUR_SERVER_IP:80>
ServerAdmin webmaster@yourdomain.com
DocumentRoot /var/www/html/matomo
ServerName yourdomain.com
ServerAlias www.yourdomain.com
ErrorLog "/var/log/httpd/yourdomain.com-error_log"
CustomLog "/var/log/httpd/yourdomain.com-access_log" combined

<Directory "/var/www/html/matomo/">
DirectoryIndex index.html index.php
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>

Start Apache

systemctl start httpd

Verify that Apache is running by checking the status of the service:

systemctl status httpd

Install certbot to handle SSL

yum install -y mod_ssl python-certbot-apache

Run Certbot to secure the Apache site

certbot --apache -d site.example.com

Reboot the server and make sure it works.

Browse to https://your.sitename.com and follow the Matomo setup steps.