The price tag of “free” for the vast majority of websites, under 10 million hits/month, has greatly contributed to Google Analytics’ popularity. In effect, Google Analytics is a freemium product intended to “upsell” web properties to the paid version, Analytics 360 (formerly known as Google Analytics Premium) starting with $150K annually.
Way before you reach 10 million hits per month though, Google Analytics will start “sampling” your data, and making inferences based on a subset of the tracked visitors. Any data above the sampling threshold will be forever lost, as Google discards it to reduce the cost of processing data for free Google Analytics accounts.
Another reason why companies are moving from Google Analytics to self-hosted analytics software such as Matomo (formerly Piwik) is for privacy & compliance concerns. The advent of privacy legislation such as the GDPR in Europe has encouraged many organizations to take a cautious approach towards tracking users’ for analytics purposes. Like most Google products, the data for Google Analytics is stored and processed on the search giant’s US-based servers. Even if a user isn’t identified by name or email address, they can be covered by the GDPR’s definitition of a “data subject” if they are a European resident.
Although Google claims that data collected from Google Analytics does not influence a website’s SEO, there is nothing stopping them from taking into account metrics such as “bounce rate” (% of visitors who navigate away from the entry page) in future revisions of their ranking algorithm. Time and time again, Google’s revisions to their search algorithms have crippled the organic search traffic to websites overnight – infuriating webmasters and bringing fomerly successful businesses to their knees.
Therefore many zealous webmasters have switched away from Google Analytics to Matomo self-hosted analytics, so that their analytics data belongs to them and them alone – as the way it should be.
Like other self-hosted apps – to use Matomo (not to be confused with the SaaS version, Matomo Cloud, hosted by the company itself), you install it on your own server – typically a virtual server with a cloud provider. It’s a PHP, Laravel, and MySQL app, so fairly straight forward to setup for anybody who is familiar with a LAMP stack. However after the basic Matomo installation is complete, there are some server and application settings to pay attention to ensure all visits are tracks and reports are being generated correctly.
Below are the system specifications recommended by Matomo depending on how many pageviews per month your website attracts. A single-node installation scales for up to 1 million pageviews, but a load balanced cluster consisting of multiple Matomo app servers is recommended for 1 million pageviews or more. In a clustered configuration, Matomo can support tracking over 1 billion monthly page views.
Tracking 100,000 pageviews per month or less
- One server is sufficient to host both the database and app server
- App server minimum recommended configuration: 2 CPU, 2 GB RAM, 50GB SSD disk.
Tracking 1 million pageviews per month or less
- One server can be sufficient to host both the database and app server
- App server minimum recommended configuration: 4 CPU, 8 GB RAM, 250GB SSD disk.
Tracking 10 million pageviews per month or less
- Two servers recommended
- 1 x App servers, at least 8 CPUs, 8 GB RAM, 100GB SSD disk.
- Or 2 x App servers, at least 4 CPUs, 4 GB RAM, 100GB SSD disk.
- 1 x Database server, at least 8 CPUs, 16 GB RAM, 400GB SSD disk.
Tracking 100 million pageviews per month or less
- Three servers at minimum recommended:
- 3 x App servers (or only 2x), with each: 16 CPUs, 8 GB RAM, 100GB SSD disk.
- 1 x Database server, at least 16 CPUs, 32 GB RAM, 1 TB SSD disk.
- or 2 x DB servers in replication
- 1 x Load balancer recommended
- 1 x CDN recommended
If you are a European company, it is preferable to install Matomo on a virtual server in Europe to avoid transferring your data subjects’ information for processing outside Europe, which requires additional disclosure under the GDPR.
The community version of Matomo is free to download from matomo.org, but instead of downloading it to your desktop (and uploading it via SCP or FTP), the best way is to wget it directly from the server which will be hosting Matomo.
Create a virtual server at your hosting provider of choice and create an A record to point a subdomain of your DNS zone, such as stats.example.com, to that server. Here are some sample commands to install Matomo on a CentOS 7 server.
Set the timezone to UTC on the server.
sudo timedatectl set-timezone UTC
Create a non-root user for Matomo.
sudo useradd -m matomo
sudo yum install httpd
sudo systemctl enable httpd && sudo systemctl start httpd
Install PHP using the Remi repo – preferably PHP 7.3 or later.
sudo yum install https://rpms.remirepo.net/enterprise/remi-release-7.rpm
sudo yum install yum-utils
sudo yum-config-manager --enable remi-php73
sudo yum install php php-curl php-gd php-cli php-mysql php-xml php-mbstring
sudo systemctl restart httpd
Install MariaDB from the EPEL repository, then create a database and database user.
sudo yum install mariadb-server mariadb
sudo systemctl enable mariadb && sudo systemctl start mariadb
mysql -uroot -p
mysql > create database matomo;
mysql > create user 'matomo’@’localhost' identified by 'password';
mysql > grant all privileges on matomo.* to 'matomo'@'localhost';
mysql > flush privileges;
mysql > exit
sudo setsebool -P httpd_can_network_connect_db 1
sudo setsebool -P httpd_can_network_connect 1
sudo setsebool -P selinuxuser_mysql_connect_enabled 1
Install Let’s Encrypt Certbot and obtain a certificate.
sudo yum install epel-release
sudo yum install certbot python2-certbot-apache
sudo certbot --apache
Download and unzip Matomo into the webroot directory, /var/www/html/.
sudo yum install wget unzip
cp -ar matomo/* .
rm -rf matomo-latest.zip 'How to install Matomo.html' matomo
chown -R apache:apache /var/www/html/
chcon -R -t httpd_sys_rw_content_t /var/www/html/
Launch the Matomo installation wizard.
Browse to stats.example.com and follow the steps in the installation wizard.
Create the matomo-archive.log file and make the apache user the owner.
sudo mkdir -p /home/matomo/log/
sudo chown -R apache:apache /home/matomo/log/
Configure cron jobs for Let’s Encrypt certificate renewal and Matomo.
sudo yum install nano
Add the following lines to the crontab.
sudo nano /etc/crontab
0 2 * * * root certbot renew
5 * * * * apache php /var/www/html/console core:archive --url=https://stats.example.com > /home/matomo/log/matomo-archive.log
Test the report archiving cron job.
sudo -u apache php /var/www/html/console core:archive --url=https://stats.example.com > /home/matomo/log/matomo-archive.log
Run a System Check and optimize Matomo.
To fix each of the following warnings for an optimized Matomo install:
How to fix Last Successful Archiving Completion – For optimal performance and a speedy Matomo, it is highly recommended to set up a crontab to automatically archive your reports, and to disable browser triggering in the Matomo settings.
While logged into the Matomo dashboard as an administrator, click the gear icon in the top right hand corner. In the left sidebar under System, select the General settings link. Under Archive reports when viewed from the browser, select No and click Save.
How to fix Max Packet Size – It is recommended to configure a ‘max_allowed_packet’ size in your MySQL database of at least 64MB. Configured is currently 1MB.
From the Linux terminal of the Matomo server, add the following line to /etc/my.cnf under the [mysqld] block.
sudo nano /etc/my.cnf
After saving the configuration, restart the database server.
sudo systemctl restart mariadb
How to fix Forced SSL Connection – We recommend using Matomo over secure SSL connections only. To prevent insecure access over http, add force_ssl = 1 to the General section in your Matomo config/config.ini.php file.
From the Linux terminal of the Matomo server, add the following line to the General section of /var/www/html/config/config.ini.php.
sudo -u apache nano /var/www/html/config/config.ini.php
force_ssl = 1
How to fix Geolocation – Geolocation works, but you are not using one of the recommended providers. If you have to import log files or do something else that requires setting IP addresses, use the PHP GeoIP 2 implementation and install maxminddb extension.
While logged into the Matomo dashboard as an administrator, click the gear icon in the top right hand corner. In the left sidebar under System, select the Geolocation link. Scroll down to the bottom of the page and click the Get Started… button under “I want to download the free GeoIP database…”
Then in the radio buttons under Location Provider on the same page, select GeoIP 2 (Php) then click Save.
After you have applied all of the above fixes, all the system checks should pass for Matomo.