In a world where data privacy and control are increasingly critical, self-hosting web analytics has become a popular alternative to third-party services. Matomo (formerly Piwik) is a powerful, open-source web analytics platform designed to give you full ownership of your data. In this guide, we’ll walk you through the process of installing Matomo on an Ubuntu 24.04 server.
Why Choose Matomo?
Matomo provides a feature-rich analytics platform that prioritizes user privacy and data ownership. Here’s why it’s a compelling choice:
- Data Ownership: Unlike third-party services, you retain full control of your analytics data.
- GDPR Compliance: Matomo is built with privacy laws in mind, making it easier to comply with regulations.
- Customizable: With a modular design, Matomo can be tailored to your needs.
- No Data Limits: You’re not bound by restrictive limits imposed by free analytics platforms.
System Requirements
Before we begin, ensure your server meets the following requirements:
- Ubuntu 24.04
- Web Server: Apache or Nginx
- Database: MySQL/MariaDB (minimum 5.5 or higher)
- PHP: Version 8.0 or higher with required extensions
- Memory: At least 512 MB RAM (1 GB recommended for large websites)
- Disk Space: Minimum 2 GB (expand as needed for logs and reports)
Step-by-Step Installation Guide
Step 1: Update Your System
Start by updating your system packages to the latest versions:
sudo apt update && sudo apt upgrade -y
Step 2: Install Apache, PHP, and MySQL
Install the necessary software stack:
sudo apt install apache2 mysql-server php libapache2-mod-php php-cli php-mysql php-zip php-gd php-xml php-mbstring php-curl unzip -y
Step 3: Secure Your MySQL Installation
Run the MySQL secure installation script:
sudo mysql_secure_installation
Follow the prompts to set a root password, remove anonymous users, and secure the database.
Step 4: Create a Database for Matomo
Log in to MySQL and create a database and user:
sudo mysql -u root -p
Inside the MySQL shell, run the following commands:
CREATE DATABASE matomo_db; CREATE USER 'matomo_user'@'localhost' IDENTIFIED BY 'strong_password'; GRANT ALL PRIVILEGES ON matomo_db.* TO 'matomo_user'@'localhost'; FLUSH PRIVILEGES; EXIT;
Replace strong_password with a secure password.
Step 5: Download and Extract Matomo
Download the latest Matomo release:
wget https://builds.matomo.org/matomo-latest.zip
Extract the archive:
unzip matomo-latest.zip sudo mv matomo /var/www/html/
Set the appropriate permissions:
sudo chown -R www-data:www-data /var/www/html/matomo sudo chmod -R 755 /var/www/html/matomo
Step 6: Configure Apache
Create a new virtual host configuration for Matomo:
sudo nano /etc/apache2/sites-available/matomo.conf
Add the following content:
<VirtualHost *:80> ServerName yourdomain.com DocumentRoot /var/www/html/matomo <Directory /var/www/html/matomo> Options Indexes FollowSymLinks AllowOverride All Require all granted </Directory> ErrorLog ${APACHE_LOG_DIR}/matomo_error.log CustomLog ${APACHE_LOG_DIR}/matomo_access.log combined </VirtualHost>
Enable the configuration and required modules:
sudo a2ensite matomo.conf sudo a2enmod rewrite sudo systemctl restart apache2
Step 7: Complete the Installation via Web Interface
Open a web browser and navigate to http://yourdomain.com. Follow the on-screen instructions to:
- Verify system requirements.
- Configure the database by entering the details you created in Step 4.
- Set up the administrator account.
- Configure your website to track.
Enhance Matomo with HTTPS
It’s highly recommended to secure your installation with HTTPS. Install a free SSL certificate using Let’s Encrypt:
sudo apt install certbot python3-certbot-apache -y sudo certbot --apache -d yourdomain.com
Renew the certificate automatically:
sudo systemctl enable certbot.timer
Conclusion
Congratulations! You’ve successfully installed and configured Matomo on your Ubuntu 24.04 server. By hosting your web analytics platform, you’re taking a significant step toward better data privacy and control. Explore Matomo’s powerful features to gain deep insights into your website’s performance while respecting user privacy.
If you found this guide helpful, consider sharing it with others who
might benefit from self-hosting Matomo. Feel free to leave comments or
questions below!