UbuntuUbuntu Based

How To Install Matomo on Ubuntu 24.04 LTS

Install Matomo on Ubuntu 24.04

Matomo, formerly known as Piwik, is a powerful open-source web analytics platform that provides valuable insights into your website’s traffic and user behavior. In this comprehensive guide, we’ll walk you through the process of installing Matomo on Ubuntu 24.04 LTS, ensuring you have a robust analytics solution up and running on your server.

Introduction

Matomo offers a privacy-focused alternative to Google Analytics, giving you full control over your data. By hosting Matomo on your own Ubuntu 24.04 LTS server, you can ensure that your website analytics remain secure and compliant with data protection regulations.

This guide is designed for system administrators and website owners who want to take charge of their analytics data. We’ll cover everything from system requirements to troubleshooting common issues, ensuring a smooth installation process.

Prerequisites

Before we begin the installation process, make sure your Ubuntu 24.04 LTS server meets the following requirements:

  • A clean installation of Ubuntu 24.04 LTS
  • Root or sudo access to the server
  • A domain name pointed to your server’s IP address
  • Basic familiarity with the Linux command line

It’s crucial to ensure your system is up-to-date before proceeding. Run the following commands to update your package lists and upgrade existing packages:

sudo apt update
sudo apt upgrade -y

System Preparation

Let’s start by preparing our Ubuntu 24.04 LTS system for Matomo installation. This involves updating the system, installing essential software, and configuring the necessary components.

Update System Packages

First, refresh your package repository and upgrade all installed packages to their latest versions:

sudo apt update
sudo apt upgrade -y

This step ensures that you have the most recent security patches and software versions, reducing the risk of compatibility issues during the Matomo installation process.

Install Essential Software

Matomo requires a web server, PHP, and a database to function properly. We’ll install the LAMP (Linux, Apache, MySQL, PHP) stack, which is a popular choice for web applications like Matomo.

Install Apache web server:

sudo apt install apache2 -y

Install MySQL database server:

sudo apt install mysql-server -y

Install PHP and required extensions:

sudo apt install php php-cli php-fpm php-json php-common php-mysql php-zip php-gd php-mbstring php-curl php-xml php-bcmath php-intl -y

After installation, restart Apache to ensure all changes take effect:

sudo systemctl restart apache2

Database Configuration

Matomo requires a dedicated database to store its data. Let’s set up a MySQL database and user for Matomo.

Secure MySQL Installation

First, run the MySQL secure installation script to improve the security of your database server:

sudo mysql_secure_installation

Follow the prompts to set a root password, remove anonymous users, disallow root login remotely, and remove the test database.

Create Matomo Database and User

Now, let’s create a database and user for Matomo. Access the MySQL prompt:

sudo mysql -u root -p

Once logged in, execute the following SQL commands to create the database and user:

CREATE DATABASE matomo;
CREATE USER 'matomouser'@'localhost' IDENTIFIED BY 'strong_password';
GRANT ALL PRIVILEGES ON matomo.* TO 'matomouser'@'localhost';
FLUSH PRIVILEGES;
EXIT;

Replace ‘strong_password‘ with a secure password of your choice.

Matomo Installation

With our system prepared and database configured, we can now proceed with downloading and setting up Matomo.

Download Latest Version

Navigate to the web root directory and download the latest version of Matomo:

cd /var/www/html
sudo wget https://builds.matomo.org/matomo-latest.zip
sudo unzip matomo-latest.zip
sudo rm matomo-latest.zip

Set Correct Permissions

Ensure that the web server has the necessary permissions to access Matomo files:


sudo chown -R www-data:www-data /var/www/html/matomo
sudo chmod -R 755 /var/www/html/matomo

Web Server Configuration

Now that Matomo files are in place, we need to configure our web server to serve the Matomo application.

Apache Configuration

Create a new Apache virtual host configuration file for Matomo:

sudo nano /etc/apache2/sites-available/matomo.conf

Add the following configuration, replacing ‘your_domain.com’ with your actual domain name:

<VirtualHost *:80>
    ServerAdmin webmaster@your_domain.com
    ServerName your_domain.com
    DocumentRoot /var/www/html/matomo

<Directory /var/www/html/matomo>
        Options 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 new virtual host and Apache rewrite module:

sudo a2ensite matomo.conf
sudo a2enmod rewrite
sudo systemctl restart apache2

Matomo Initial Setup

With the web server configured, you can now access the Matomo web-based installation wizard to complete the setup process.

Open your web browser and navigate to http://your_domain.com/matomo. You should see the Matomo welcome screen.

Follow these steps to complete the installation:

1. Click “Next” on the welcome screen.
2. Review the system check results and address any issues if necessary.
3. Enter your MySQL database details (database name, username, and password).
4. Create your Matomo superuser account.
5. Enter details about the first website you want to track.
6. Copy the provided JavaScript tracking code to include on your website.

Once you’ve completed these steps, you’ll have access to your Matomo dashboard.

Install Matomo on Ubuntu 24.04

Security Considerations

To ensure the security of your Matomo installation, consider implementing the following measures:

Enable SSL/TLS

Secure your Matomo instance with HTTPS by obtaining and installing an SSL certificate. You can use Let’s Encrypt for free SSL certificates:

sudo apt install certbot python3-certbot-apache
sudo certbot --apache -d your_domain.com

Regular Updates

Keep Matomo and your server software up-to-date to protect against known vulnerabilities. Enable automatic security updates for Ubuntu:

sudo apt install unattended-upgrades
sudo dpkg-reconfigure -plow unattended-upgrades

Firewall Configuration

Configure UFW (Uncomplicated Firewall) to restrict access to your server:

sudo ufw allow OpenSSH
sudo ufw allow 'Apache Full'
sudo ufw enable

Troubleshooting Common Issues

Even with careful installation, you may encounter some issues. Here are solutions to common problems:

Permission Errors

If you encounter permission-related errors, double-check the ownership and permissions of the Matomo directory:

sudo chown -R www-data:www-data /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 {} \;

Database Connection Issues

If Matomo can’t connect to the database, verify your database credentials and ensure the MySQL service is running:

sudo systemctl status mysql

PHP Configuration

Matomo may require specific PHP settings. Edit your php.ini file to adjust these settings:

sudo nano /etc/php/8.2/apache2/php.ini

Look for and modify these values:

memory_limit = 256M
max_execution_time = 300
post_max_size = 64M
upload_max_filesize = 64M

Remember to restart Apache after making changes:

sudo systemctl restart apache2

Congratulations! You have successfully installed Matomo. Thanks for using this tutorial for installing Matomo Web Analytics on Ubuntu 24.04 LTS system. For additional help or useful information, we recommend you check the Matomo website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is an experienced Linux enthusiast and technical writer with a passion for open-source software. With years of hands-on experience in various Linux distributions, r00t has developed a deep understanding of the Linux ecosystem and its powerful tools. He holds certifications in SCE and has contributed to several open-source projects. r00t is dedicated to sharing her knowledge and expertise through well-researched and informative articles, helping others navigate the world of Linux with confidence.
Back to top button