How To Install Matomo on CentOS Stream 10
In this tutorial, we will show you how to install Matomo on CentOS Stream 10. Matomo is a powerful, open-source alternative to Google Analytics that provides complete data ownership and privacy compliance. This comprehensive guide will walk you through installing Matomo on CentOS Stream 10, the latest version of the Enterprise Linux distribution. By following these systematic steps, you’ll have your self-hosted analytics platform up and running efficiently.
Introduction to Matomo and CentOS Stream 10
CentOS Stream 10, codenamed “Coughlan,” represents the cutting edge of Enterprise Linux development and serves as the upstream branch for future Red Hat Enterprise Linux (RHEL) minor versions. Released in December 2024, it offers significant improvements over previous versions, including Linux kernel 6.12, Python 3.12, and GNOME 47. Matomo, formerly known as Piwik, has become increasingly popular for those seeking a privacy-focused web analytics solution that offers full data ownership and control.
Matomo provides robust features comparable to Google Analytics, including visit tracking, conversion monitoring, goal setting, and comprehensive reporting capabilities. What sets Matomo apart is its emphasis on privacy compliance, making it an excellent choice for organizations concerned about data protection regulations such as GDPR. By hosting Matomo on your own CentOS Stream 10 server, you maintain complete control over your analytics data while benefiting from the stability and security of Enterprise Linux.
This guide assumes you have a basic understanding of Linux administration and command-line operations. While the installation process requires several steps, each is clearly explained to ensure a successful deployment regardless of your experience level. Let’s begin by examining the system requirements and preparing your CentOS Stream 10 environment for Matomo installation.
System Requirements for Matomo Installation
Hardware Requirements
Before proceeding with the installation, ensure your server meets the minimum hardware requirements for running Matomo efficiently. For small to medium-sized websites, allocate at least 2GB of RAM and 2 CPU cores. Larger sites with significant traffic will benefit from 4GB or more RAM and additional CPU resources. Storage requirements depend on your retention policies, but starting with at least 20GB of available disk space is recommended to accommodate both the operating system and Matomo’s data storage needs.
Software Requirements
Matomo has specific software dependencies that must be satisfied for proper operation. CentOS Stream 10 provides an excellent foundation, but you’ll need to install the following components:
- Web server: Apache, Nginx, or another compatible HTTP server
- Database: MySQL 5.5+ or MariaDB (MySQL 8.0+ or MariaDB 10.3+ recommended)
- PHP: Version 7.2.5 or higher (PHP 8.1+ recommended for optimal performance)
- PHP extensions: pdo, pdo_mysql (or mysqli), gd, xml, curl, and mbstring
The installation process outlined in this guide will cover setting up all these components on your CentOS Stream 10 system, ensuring compatibility and optimal performance for your Matomo instance.
Preparing Your CentOS Stream 10 Server
Updating the System
Begin by ensuring your CentOS Stream 10 installation is fully updated with the latest security patches and software updates. Open a terminal session and execute the following commands:
sudo dnf clean all
sudo dnf update -y
This comprehensive update process may take several minutes depending on your server’s internet connection speed and the number of packages requiring updates. It’s crucial to start with a fully updated system to avoid potential compatibility issues during the Matomo installation process.
Setting the Correct Timezone
Proper timezone configuration ensures accurate timestamp recording in your analytics data. Configure your server’s timezone using the timedatectl
command:
sudo timedatectl list-timezones
sudo timedatectl set-timezone 'Region/City'
Replace ‘Region/City’ with your appropriate timezone, such as ‘America/New_York’ or ‘Europe/London’. Correct timezone settings are essential for accurate reporting and data analysis within Matomo.
Installing Essential Packages
Several utility packages will facilitate the installation process. Install these preliminary tools with:
sudo dnf install wget unzip vim nano -y
These utilities provide file downloading capabilities (wget), archive extraction (unzip), and text editing functionality (vim and nano) that will be useful throughout the installation process and for future server maintenance.
Configuring Firewall
CentOS Stream 10 uses firewalld by default. Configure it to allow HTTP and HTTPS traffic to reach your web server:
sudo firewall-cmd --permanent --zone=public --add-service=http
sudo firewall-cmd --permanent --zone=public --add-service=https
sudo firewall-cmd --reload
These commands enable incoming connections on ports 80 (HTTP) and 443 (HTTPS), which are essential for accessing your Matomo installation through a web browser. The firewall configuration ensures your analytics platform is accessible while maintaining server security.
Installing the LAMP Stack
Installing Apache Web Server
Apache is one of the most popular and well-supported web servers available for Linux systems. Install Apache on your CentOS Stream 10 server with:
sudo dnf install httpd -y
After installation, start the Apache service and enable it to launch automatically on system boot:
sudo systemctl start httpd
sudo systemctl enable httpd
Verify Apache is running correctly by accessing your server’s IP address in a web browser. You should see the default Apache test page, confirming the web server is operational and responding to requests.
Installing MariaDB Database Server
MariaDB is the recommended database server for Matomo installations. Install it with:
sudo dnf install mariadb-server mariadb -y
Start and enable the MariaDB service:
sudo systemctl start mariadb
sudo systemctl enable mariadb
Secure your MariaDB installation by running the security script:
sudo mysql_secure_installation
This interactive script will guide you through setting a root password, removing anonymous users, disallowing remote root login, removing the test database, and reloading privileges. For optimal security, answer “Y” to all prompts during this process.
Installing PHP and Required Extensions
Matomo requires PHP and several specific extensions. Install PHP 8.2 (or later) and all necessary components:
sudo dnf install php php-mysqlnd php-fpm php-json php-dom php-gd php-mbstring php-xml php-curl -y
Configure PHP for optimal performance with Matomo by editing the php.ini file:
sudo nano /etc/php.ini
Locate and modify the following values:
upload_max_filesize = 16M
post_max_size = 16M
memory_limit = 256M
max_execution_time = 300
max_input_time = 300
Save the changes and restart the Apache service to apply the new PHP configuration:
sudo systemctl restart httpd
These PHP settings provide optimal performance for Matomo while ensuring sufficient resources for processing analytics data, especially for websites with significant traffic volumes.
Creating a Database for Matomo
Logging into MariaDB
Access the MariaDB command line interface using:
sudo mysql -u root -p
Enter the root password you set during the mysql_secure_installation process.
Creating a Dedicated Database and User
Create a dedicated database and user account for Matomo with the following SQL commands:
CREATE DATABASE matomo;
CREATE USER 'matomo_user'@'localhost' IDENTIFIED BY 'secure_password';
GRANT ALL PRIVILEGES ON matomo.* TO 'matomo_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;
Replace ‘secure_password’ with a strong, unique password. Using a separate database and dedicated user account follows security best practices by isolating Matomo data and limiting access privileges.
Verifying Database Creation
Confirm your database was created successfully by logging in with the new user:
mysql -u matomo_user -p matomo
When prompted, enter the password you created. If you can successfully connect, your database is properly configured. Exit the MySQL prompt:
EXIT;
The database creation process establishes a secure environment for storing your analytics data. The dedicated user account provides the necessary access privileges while maintaining proper security isolation. The database name, username, and password will be required during the Matomo web-based installation process, so make note of these credentials for future reference.
Downloading and Configuring Matomo
Downloading the Latest Matomo Release
Navigate to your web server’s document root directory and download the latest Matomo package:
cd /var/www/html
sudo wget https://builds.matomo.org/matomo.zip
Extract the downloaded archive:
sudo unzip matomo.zip
Set appropriate ownership and permissions:
sudo chown -R apache:apache matomo
sudo chmod -R 755 matomo
These commands ensure that the web server has proper access to the Matomo files while maintaining security through appropriate permissions.
Creating a Dedicated Virtual Host (Optional)
For improved organization and security, create a dedicated Apache virtual host for Matomo:
sudo nano /etc/httpd/conf.d/matomo.conf
Add the following configuration, replacing example.com with your domain:
<VirtualHost *:80>
ServerName analytics.example.com
DocumentRoot /var/www/html/matomo
<Directory /var/www/html/matomo>
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog /var/log/httpd/matomo_error.log
CustomLog /var/log/httpd/matomo_access.log combined
</VirtualHost>
Save the file and restart Apache:
sudo systemctl restart httpd
Creating Required Directories
Matomo requires specific directories for temporary files and configuration:
sudo mkdir -p /var/www/html/matomo/tmp
sudo mkdir -p /var/www/html/matomo/config
sudo chown -R apache:apache /var/www/html/matomo/tmp
sudo chown -R apache:apache /var/www/html/matomo/config
These directories store temporary files and configuration data that Matomo needs for proper operation. The correct permissions ensure the web server can write to these locations when necessary.
Completing Web-Based Installation
Accessing the Matomo Installer
Open your web browser and navigate to your Matomo installation:
http://your_server_ip/matomo
Or if you configured a virtual host:
http://analytics.example.com
You’ll be greeted by the Matomo installation wizard, which will guide you through the remaining setup steps.
System Check
The first step performs a system check to verify that your server meets all requirements. If any issues are detected, Matomo will provide guidance on resolving them. Most commonly, these relate to PHP extensions or directory permissions, which should already be properly configured if you followed the previous steps.
Database Configuration
Enter the database information you created earlier:
- Database Server: localhost
- Login: matomo_user
- Password: the secure password you created
- Database Name: matomo
- Table Prefix: matomo_ (or customize as desired)
Click “Next” to proceed. Matomo will create the necessary database tables and schema.
Creating the Administrator Account
Set up your administrator account by providing:
- Super User Login: Choose a username
- Password: Create a strong password
- Email: Your email address
- Organization Name: Your company or website name
These credentials will be used to access the Matomo administration interface, so choose a secure password and keep it in a safe place.
Configuring Your First Website
Add your first website to track by providing:
- Website Name: The name of your site
- Website URL: The full URL including
http://
orhttps://
- Timezone: Select the appropriate timezone for accurate reporting
- Ecommerce: Enable if applicable
Click “Next” to complete the setup. Matomo will generate the tracking code you’ll need to insert into your website to begin collecting analytics data.
Securing Your Matomo Installation
Implementing HTTPS with Let’s Encrypt
For enhanced security, configure HTTPS using Let’s Encrypt certificates:
sudo dnf install epel-release -y
sudo dnf install certbot python3-certbot-apache -y
sudo certbot --apache -d analytics.example.com
Follow the prompts to complete the certificate installation and configure automatic redirects from HTTP to HTTPS.
Setting Up Proper File Permissions
Review and tighten file permissions:
sudo find /var/www/html/matomo -type f -exec chmod 644 {} \;
sudo find /var/www/html/matomo -type d -exec chmod 755 {} \;
sudo chmod -R 750 /var/www/html/matomo/tmp
sudo chmod -R 750 /var/www/html/matomo/config
These commands ensure files have appropriate read-only permissions while allowing the web server to write to specific directories when necessary.
Configuring Security Settings in Matomo
Log in to your Matomo administration interface and navigate to Settings → Security to:
- Enable two-factor authentication for administrator accounts
- Configure password policies
- Set up IP address whitelisting for administrative access
- Enable brute force protection
These settings significantly enhance your Matomo installation’s security posture by implementing multiple layers of protection against unauthorized access attempts.
Adding the Tracking Code to Your Websites
Retrieving Your Tracking Code
Log in to Matomo and navigate to Administration → Tracking Code. Copy the generated JavaScript tracking code, which will look similar to:
<!-- Matomo -->
<script>
var _paq = window._paq = window._paq || [];
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
var u="https://analytics.example.com/";
_paq.push(['setTrackerUrl', u+'matomo.php']);
_paq.push(['setSiteId', '1']);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
})();
</script>
<!-- End Matomo Code -->
Implementing the Tracking Code
Add this code to each page of your website, ideally in the <head>
section before the closing </head>
tag. For content management systems like WordPress, Drupal, or Joomla, you can use dedicated plugins to simplify this process.
The tracking code initiates data collection for your website visitors, recording page views, visitor sources, and other behavioral metrics that will appear in your Matomo dashboard.
Congratulations! You have successfully installed Matomo. Thanks for using this tutorial for installing Matomo web analytics on your CentOS Stream 10 system. For additional help or useful information, we recommend you check the official Matomo website.