How To Install Matomo on Fedora 42
Matomo stands as a powerful open-source web analytics platform that gives website owners complete control over their data. Unlike cloud-based alternatives, self-hosting Matomo on your Fedora 42 system ensures maximum privacy and customization options. This comprehensive guide walks you through the entire installation process, from preparing your system to configuring automated tasks for maintenance.
Prerequisites for Installing Matomo
Before diving into the installation process, ensure your Fedora 42 system meets the necessary requirements for running Matomo effectively. The hardware specifications needed will depend on your expected traffic volume, but generally, you’ll need:
- At least 2GB RAM (4GB+ recommended for medium to high traffic sites)
- 1GB free disk space (more for growing analytics data)
- A CPU with at least 2 cores
- Root or sudo privileges on your Fedora system
Additionally, verify that your Fedora version is correct by running:
cat /etc/fedora-release
The output should confirm you’re running Fedora 42.
Step 1: Updating Your Fedora System
Starting with an updated system ensures compatibility and security. Open your terminal and execute the following commands:
sudo dnf check-update
sudo dnf upgrade -y
These commands refresh your package repositories and upgrade all installed packages to their latest versions. This crucial first step prevents potential conflicts during installation and ensures your system has the latest security patches.
Wait for the update process to complete. You can verify the success of your system update by checking if any errors appeared during the process.
Step 2: Installing and Configuring Apache Web Server
Matomo requires a web server to function, with Apache being the most commonly used option. Install Apache with the following command:
sudo dnf install httpd -y
After installation, start the Apache service and enable it to launch at system boot:
sudo systemctl start httpd
sudo systemctl enable httpd
Verify that Apache is running properly:
sudo systemctl status httpd
You should see “active (running)” in the output, confirming that Apache is operational.
For optimal performance with Matomo, enable these essential Apache modules:
sudo dnf install mod_ssl -y
sudo systemctl restart httpd
Test your Apache installation by opening a web browser and navigating to your server’s IP address or hostname. You should see the default Apache test page, indicating successful installation.
Step 3: Installing PHP and Required Extensions
Matomo requires PHP and several extensions to function correctly. For Fedora 42, we’ll install PHP 8.x, which offers excellent performance and compatibility with Matomo.
sudo dnf install php php-cli php-fpm php-mysqlnd php-zip php-devel php-gd php-mbstring php-curl php-xml php-pear php-bcmath php-json php-dom -y
This comprehensive command installs PHP along with all the extensions required by Matomo:
- php-mysqlnd: For database connectivity
- php-zip: For handling zip archives
- php-gd: For image processing
- php-mbstring: For multibyte string handling
- php-curl: For remote API connections
- php-xml: For XML processing
- php-json: For JSON handling
- php-dom: For DOM manipulation
After installation, optimize PHP for Matomo by modifying the PHP configuration:
sudo nano /etc/php.ini
Make the following adjustments for better performance:
memory_limit = 256M
max_execution_time = 300
post_max_size = 32M
upload_max_filesize = 32M
date.timezone = Your/Timezone
Replace “Your/Timezone” with your actual timezone (e.g., “America/New_York”).
Save the file and restart Apache to apply the changes:
sudo systemctl restart httpd
Step 4: Installing MariaDB/MySQL Database
Matomo stores all analytics data in a database, with MariaDB being an excellent choice for Fedora 42. Install MariaDB with:
sudo dnf install mariadb-server -y
Start the MariaDB service and enable it to launch at boot:
sudo systemctl start mariadb
sudo systemctl enable mariadb
Secure your MariaDB installation:
sudo mysql_secure_installation
During this process, you’ll be asked several questions:
- Enter the current root password (press Enter if none exists)
- Set a new root password (strongly recommended)
- Answer “Y” to remove anonymous users
- Answer “Y” to disallow remote root login
- Answer “Y” to remove test database
- Answer “Y” to reload privilege tables
These security measures ensure your database is protected from unauthorized access.
Step 5: Creating a Database for Matomo
Now create a dedicated database and user for Matomo. Access the MariaDB command line:
sudo mysql -u root -p
Enter the root password you set previously. Then execute these SQL commands:
CREATE DATABASE matomo;
CREATE USER 'matomouser'@'localhost' IDENTIFIED BY 'your_strong_password';
GRANT ALL PRIVILEGES ON matomo.* TO 'matomouser'@'localhost';
FLUSH PRIVILEGES;
EXIT;
Replace ‘your_strong_password’ with a secure password. This creates:
- A database named “matomo”
- A user named “matomouser” with full privileges on the matomo database
- Proper security restrictions limiting the user to local connections only
Record these database credentials as you’ll need them during the web installation process.
Step 6: Downloading and Installing Matomo
With our environment prepared, we can now download and install Matomo itself:
cd /tmp
sudo wget https://builds.matomo.org/matomo.zip
sudo unzip matomo.zip -d /var/www/html/
Verify the integrity of the downloaded package by checking its SHA256 checksum against the official value from the Matomo website:
sha256sum matomo.zip
Set proper permissions for the Matomo files:
sudo chown -R apache:apache /var/www/html/matomo/
sudo find /var/www/html/matomo/ -type d -exec chmod 755 {} \;
sudo find /var/www/html/matomo/ -type f -exec chmod 644 {} \;
These permissions ensure that:
- The web server (Apache) owns all Matomo files
- Directories have proper executable permissions (755)
- Files have proper read/write permissions (644)
This security-focused approach prevents unauthorized access while allowing Matomo to function correctly.
Step 7: Configuring Apache Virtual Host for Matomo
Create a dedicated virtual host configuration for Matomo:
sudo nano /etc/httpd/conf.d/matomo.conf
Add the following configuration:
<VirtualHost *:80>
ServerAdmin webmaster@your-domain.com
DocumentRoot /var/www/html/matomo
ServerName matomo.your-domain.com
<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>
Replace “your-domain.com” with your actual domain name. This configuration:
- Creates a dedicated virtual host for Matomo
- Enables .htaccess support through AllowOverride All
- Sets up proper logging for troubleshooting
After saving the file, check the configuration for syntax errors:
sudo apachectl configtest
If the test shows “Syntax OK”, restart Apache:
sudo systemctl restart httpd
Step 8: Adjusting SELinux and Firewall Settings
Fedora uses SELinux by default, which can restrict Matomo’s functionality. Configure proper SELinux contexts:
sudo semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/html/matomo/tmp(/.*)?"
sudo semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/html/matomo/config(/.*)?"
sudo restorecon -Rv /var/www/html/matomo/
Configure the firewall to allow HTTP and HTTPS traffic:
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload
Verify that the firewall settings are active:
sudo firewall-cmd --list-all
You should see “http” and “https” listed under services, confirming that web traffic is allowed through the firewall.
Step 9: Running the Matomo Web Installer
With all components configured, you can now run the Matomo web installer:
- Open your web browser and navigate to your Matomo domain or IP address (e.g., h
ttp://matomo.your-domain.com
orhttp://your-server-ip/matomo
) - The installer will perform a system check to ensure all requirements are met. If any issues are found, resolve them before continuing.
- When prompted, enter your database information:
- Database Server: localhost
- Login: matomouser
- Password: your_strong_password (the one you set earlier)
- Database Name: matomo
- Table Prefix: matomo_ (recommended for security)
- Create your administrator account with a strong username and password.
- Configure your first website by entering:
- Website name
- Website URL
- Time zone
- Additional settings as needed
- Once the installation completes, you’ll see a tracking code that you can add to your website.
The installer creates all necessary database tables and configuration files automatically. After completion, you’ll be redirected to the Matomo dashboard.
Step 10: Post-Installation Configuration
After the basic installation, optimize your Matomo instance with these important configurations:
Security Settings
Navigate to Administration > Privacy to:
- Configure data anonymization
- Set data retention policies
- Enable IP anonymization
Performance Optimization
Under Administration > System > General Settings:
- Enable browser caching
- Set report generation to be processed in the background
- Configure archiving settings based on your traffic volume
Email Notifications
Configure email settings under Administration > System > Email:
- Set up SMTP details for reliable email delivery
- Configure system alerts for important events
- Set up scheduled reports for stakeholders
These post-installation configurations enhance security, performance, and usability of your Matomo installation, ensuring it operates efficiently even as your website traffic grows.
Step 11: Setting Up Tracking
To start collecting analytics data, you need to implement Matomo’s tracking code on your website:
- In your Matomo dashboard, go to Administration > Tracking Code
- Copy the provided JavaScript tracking code
- Add this code to all pages of your website, just before the closing
</head>
tag
The tracking code looks similar to:
<!-- Matomo -->
<script>
var _paq = window._paq = window._paq || [];
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
var u="//matomo.your-domain.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 -->
Verify that tracking is working properly by visiting your website and then checking the Real-time > Visitors Map in Matomo. You should see your visit recorded immediately.
Step 12: Configuring Automated Tasks
For optimal performance, set up automated maintenance tasks using cron jobs:
sudo nano /etc/cron.d/matomo
Add the following lines:
# Process Matomo archive reports every hour
0 * * * * apache /usr/bin/php /var/www/html/matomo/console core:archive --url=https://matomo.your-domain.com/ > /dev/null 2>&1
# Optimize database tables weekly
0 3 * * 0 apache /usr/bin/php /var/www/html/matomo/console core:run-scheduled-tasks > /dev/null 2>&1
# Database cleanup monthly
0 4 1 * * apache /usr/bin/php /var/www/html/matomo/console database:optimize > /dev/null 2>&1
Save the file and set proper permissions:
sudo chmod 644 /etc/cron.d/matomo
These automated tasks ensure that:
- Reports are always up-to-date
- Database tables are regularly optimized
- Maintenance tasks run without manual intervention
Troubleshooting Common Issues
If you encounter problems during or after installation, here are solutions to common issues:
Database Connection Errors
- Verify database credentials in config/config.ini.php
- Ensure the MySQL/MariaDB service is running
- Check that the database user has proper permissions
Permission Issues
If Matomo reports permission errors:
sudo chown -R apache:apache /var/www/html/matomo/tmp /var/www/html/matomo/config
sudo chmod -R 755 /var/www/html/matomo/tmp /var/www/html/matomo/config
PHP Configuration Problems
If Matomo indicates missing PHP extensions:
sudo dnf install php-extension-name -y
sudo systemctl restart httpd
Blank Pages or 500 Errors
Check Apache error logs for details:
sudo tail -f /var/log/httpd/matomo_error.log
Security Best Practices
Enhance your Matomo installation’s security with these best practices:
Implement HTTPS
Secure your analytics data with HTTPS using Let’s Encrypt:
sudo dnf install certbot python3-certbot-apache -y
sudo certbot --apache -d matomo.your-domain.com
Regular Updates
Keep Matomo updated to patch security vulnerabilities:
sudo -u apache php /var/www/html/matomo/console core:update
Access Restrictions
Limit access to the admin interface by IP in your Apache configuration:
<Directory /var/www/html/matomo/index.php>
Require ip 192.168.1.0/24
</Directory>
Data Retention
Configure data retention policies to comply with privacy regulations like GDPR, limiting how long raw visitor data is stored.
Congratulations! You have successfully installed Matomo. Thanks for using this tutorial for installing Matomo web analytics on your Fedora 42 Linux system. For additional help or useful information, we recommend you check the official Matomo website.