Skip to content
Follow
CMS

How to Install Matomo Analytics with Nginx on Ubuntu 24.04

Richard
Written by
Richard
Jun 9, 2024 Updated Sep 15, 2026 6 min read
Matomo featured image
Matomo featured image

Installing Matomo Analytics with Nginx on Ubuntu 24.04 gives you a private way to track website visitors without sharing data with third-party companies. Matomo is a free open-source tool that replaces Google Analytics on your own server, and Nginx is a fast web server that handles traffic.

Advertisement

Running this setup on Ubuntu 24.04 LTS puts you in full control of your visitor logs and site statistics.

⚡ Quick Answer

Install Nginx, MariaDB, and PHP-FPM using apt. Create a database and user in MariaDB for Matomo. Configure Nginx to serve your Matomo installation.

Advertisement

Install Nginx HTTP server on Ubuntu

To install Nginx on Ubuntu 24.04 for your Matomo Analytics setup, open your terminal and run the commands sudo apt update followed by sudo apt install nginx. This downloads and sets up the Nginx HTTP server on your system so it can serve your web pages properly.

To do that, open the Ubuntu terminal and run the commands below to install the Nginx web server.

🐧Bash / Shell
sudo apt update
sudo apt install nginx

Once Nginx is installed, the commands below can start, stop, and enable the Nginx web server to start automatically when your server boots up.

🐧Bash / Shell
sudo systemctl stop nginx
sudo systemctl start nginx
sudo systemctl enable nginx

You can test the Nginx web server by opening your web browser and browsing to the server’s localhost or IP address.

Advertisement

http://localhost

Default Nginx welcome page displayed after installation on Ubuntu 24.04
Default Nginx welcome page displayed after installation on Ubuntu 24.04

When you see the Welcome to nginx! page, it means the Nginx HTTP server is successfully installed.

Additional help on installing Nginx on Ubuntu is in the link below.

How to install Nginx on Ubuntu

Advertisement

Install the MariaDB database server on Ubuntu

MariaDB database server installation on Ubuntu 24.04 provides the backend storage required to save your Matomo Analytics data. Open your terminal and run the package manager commands to download and set up the database service on your server.

To install and use the MariaDB database server, use the instructions below.

Open the Ubuntu terminal and run the commands below to install the MariaDB database server.

🐧Bash / Shell
sudo apt update
sudo apt install mariadb-server

Once the MariaDB database server is installed, use the commands below to stop, start, and enable the MariaDB server to start automatically when the server boots.

Advertisement
🐧Bash / Shell
sudo systemctl stop mariadb
sudo systemctl start mariadb
sudo systemctl enable mariadb

Run the following commands to validate and test if the MariaDB database server is installed successfully.

🐧Bash / Shell
sudo mariadb

Once you run the commands above, it will log you onto the MariaDB console and display a message similar to the one below.

💻Code
Welcome to the MariaDB monitor.  Commands end with ; or g.
Your MariaDB connection id is 32
Server version: 10.11.2-MariaDB-1 Ubuntu 23.04

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.

MariaDB [(none)]> 

The message tells you that the server is installed successfully.

Additional help on installing MariaDB.

Advertisement

Create a Matomo database

Creating a Matomo database in MariaDB gives the analytics platform a secure place to store visitor tracking data. Log into your database console and run the SQL commands to create a dedicated database and user account with the right permissions before running the web installer.

As part of the setup, we will create a matomodb database and a user account called matomodbuser.

Finally, we'll grant the matomodbuser full access to the matomodb database.

All the database steps above can be done using the commands below:

Advertisement

But first, log on to the MariaDB database server:

🐧Bash / Shell
sudo mariadb

Then run the commands below to complete the steps:

💻Code
CREATE DATABASE matomodb CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
CREATE USER matomodbuser@localhost IDENTIFIED BY 'type_your_password_here';
GRANT ALL ON matomodb.* TO matomodbuser@localhost WITH GRANT OPTION;
FLUSH PRIVILEGES;
exit
⚠️WarningEnsure to replace 'type_your_password_here 'with your password.

Install PHP-FPM on Ubuntu Linux

Installing PHP-FPM on Ubuntu 24.04 allows your server to process the PHP code that powers Matomo Analytics. Run the terminal command to install PHP-FPM along with the required extensions like curl, gd, and mysql that Matomo needs to function correctly.

Advertisement

Run the commands below to install PHP-FPM.

🐧Bash / Shell
sudo apt install php-fpm php-intl php-mysql php-curl php-cli php-zip php-xml php-gd php-common php-mbstring php-xmlrpc php-json php-sqlite3 php-soap php-ldap php-zip

Additional help on installing PHP

How to install PHP on Ubuntu Linux

Download Matomo files

Downloading Matomo files directly to your Ubuntu server gets you the latest version of the analytics software. Grab the archive from the official site, extract the application files, and move them into your Nginx web root directory so visitors can access the setup wizard.

💡TipTo always install the latest version, check the Matomo's download page.

If a new version is available, replace the version number in the link below.

First, navigate to the /tmp/ directory and download Matomo files. After unzipping the file, move the content into the Matomo folder in the Nginx root directory.

The final step is to change the permissions. This will allow the Nginx web server to interact safely with the files, ensuring a secure environment for your Matomo installation.

⬛Command Prompt
cd /tmp
wget https://builds.matomo.org/matomo-latest.zip
sudo unzip matomo-latest.zip -d /var/www/
sudo chown -R www-data:www-data /var/www/matomo

Once you have completed all the above steps, continue configuring the Nginx web server below to serve the Matomo content.

Run the commands below to create a Nginx server block file for Matomo.

🐧Bash / Shell
sudo nano /etc/nginx/sites-available/matomo.conf

Then, copy and paste the content block below into the Nginx server block.

🐘PHP
server {
listen 80;
listen [::]:80;
root /var/www/matomo;
index index.php;
server_name matomo.example.com;


location / {
try_files $uri $uri/ =404;
}


location ~ .php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php8.3-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}

location ~ js/container_.*_preview.js$ {
expires off;
add_header Cache-Control 'private, no-cache, no-store';
}

## deny access to all other .php files
location ~* ^.+.php$ {
deny all;
return 403;
}
}

Save the file.

You must enable the Nginx virtual host for Matomo Analytics and restart the Nginx server. Run `sudo ln -s /etc/nginx/sites-available/matomo.conf /etc/nginx/sites-enabled/` to create a link, then `sudo systemctl restart nginx` to apply the changes and make Matomo Analytics accessible.

🐧Bash / Shell
sudo ln -s /etc/nginx/sites-available/matomo.conf /etc/nginx/sites-enabled/
sudo systemctl restart nginx.service

Setup Let's Encrypt SSL/TLS for Matomo

Setting up Let's Encrypt SSL/TLS for Matomo encrypts your analytics traffic and enables secure HTTPS connections on your Nginx server. Configure a free security certificate using Certbot to protect your login details and visitor data from prying eyes.

Please read the post below for additional resources on installing and creating Let's Encrypt SSL certificates for Nginx.

How to set up Let's Encrypt SSL certificate for Nginx on Ubuntu Linux

Once you have restarted the Nginx web server, open your browser and browse to the server hostname or IP address defined in the Nginx server block.

💻Code
http://matomo.example.com

A Matomo installation wizard page should appear. Next to begin.

Matomo installation wizard welcome
Matomo installation wizard welcome

On the next page, confirm all requirements are met, then continue.

Matomo installation wizard requirements
Matomo installation wizard requirements

Next, enter the database name, account, and password and continue.

Matomo installation wizard database connection
Matomo installation wizard database connection

Next, create an admin account and continue.

Matomo installation wizard admin account
Matomo installation wizard admin account

On the next screen, type in your site details and continue

Matomo installation wizard website details
Matomo installation wizard website details

Copy the JavaScript code if you'd like and continue.

Matomo installation wizard javascript code
Matomo installation wizard javascript code

Your Matomo site should be set up and ready to use.

Matomo installation wizard complete
Matomo installation wizard complete

That should do it!

Conclusion:

  • Matomo Analytics offers powerful open-source web analytics features for detailed insights into website visitor behavior.
  • Installing Matomo Analytics with Nginx on Ubuntu 24.04 leverages the performance and reliability of Nginx as a web server, along with Matomo's robust analytics capabilities.
  • This combination allows for comprehensive monitoring and analysis of website traffic, user engagement, and other vital metrics with utmost security and efficiency.
  • Nginx optimizes Matomo Analytics' performance, ensuring the analytics platform's smooth and effective operation within a secure and reliable system.
  • Following the step-by-step guide, users can install Matomo Analytics with Nginx on Ubuntu 24.04 and set up a secure and efficient web analytics environment.

Was this guide helpful?

Was this helpful?
Richard

About the Author

Richard

Tech Writer, IT Professional

Richard is a writer at Geek Rewind who turns complex IT tasks into clear, step-by-step guides. He draws on years of hands-on experience in system administration and enterprise IT operations, focusing on Windows, Linux and WordPress: the problems people actually run into, and the fixes that work. His server and WordPress guides come from systems he runs himself. Richard builds and maintains the platform behind Geek Rewind, from its Ubuntu servers and Nginx configuration to its custom WordPress plugins. Many new tutorials start with readers' questions, and he's always glad to answer them in the comments.

Advertisement

📚 Related Tutorials

How to Install Nginx on Ubuntu Linux
Ubuntu Linux How to Install Nginx on Ubuntu Linux
Install MySQL and MariaDB on Ubuntu: A Step-by-Step Guide
Ubuntu Linux Install MySQL and MariaDB on Ubuntu: A Step-by-Step Guide
How to Install GNOME Desktop on Ubuntu 24.04
Ubuntu Linux How to Install GNOME Desktop on Ubuntu 24.04
How to Install KDE Desktop on Ubuntu 24.04
Ubuntu Linux How to Install KDE Desktop on Ubuntu 24.04

No comments yet — be the first to share your thoughts!

Leave a Comment

Your email address will not be published. Required fields are marked *