Mets Minor League Blog

Music theory, instruments and musicians

Mets Minor League Blog

Music theory, instruments and musicians

How to Install Matomo Analytics with Nginx on Ubuntu 24.04

How to Install Matomo Analytics with Nginx on Ubuntu 24.04

Implementing an analytics platform like Matomo on your website allows you to gain valuable insights into visitor behavior, traffic sources, and engagement metrics. When paired with a robust server setup like Ubuntu 24.04 and Nginx, you can host your own analytics solution securely and efficiently. This guide walks you through the process of installing and configuring Matomo Analytics on an Ubuntu 24.04 server using Nginx, ensuring your site’s data privacy and control are maximized. Before starting, make sure you have a fresh Ubuntu 24.04 server with root or sudo access, a registered domain name pointing to your server, and basic familiarity with terminal commands and server management.

What You’ll Need

  • Ubuntu 24.04 server with root or sudo privileges
  • Domain name pointing to your server’s IP address
  • Basic knowledge of Linux command line
  • Access to a terminal or SSH client
  • SSL certificate (recommended for security, can use Let’s Encrypt)

Step-by-Step

  1. Update your system packages: Log into your server via SSH and run:
    sudo apt update && sudo apt upgrade -y This ensures all packages are current, reducing compatibility issues.
  2. Install necessary dependencies: Install PHP, MariaDB (or MySQL), and other required packages:
    sudo apt install nginx php-fpm php-mysql php-gd php-xml php-mbstring php-curl php-bcmath php-zip mariadb-server unzip -y
  3. Secure your MariaDB installation: Run:
    sudo mysql_secure_installation and follow prompts to set a root password and secure your database server.
  4. Create a database and user for Matomo: Log into MySQL:
    sudo mysql -u root -p Then run:
    CREATE DATABASE matomo_db CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; CREATE USER 'matomo_user'@'localhost' IDENTIFIED BY 'strong_password'; GRANT ALL PRIVILEGES ON matomo_db.* TO 'matomo_user'@'localhost'; FLUSH PRIVILEGES; EXIT;
  5. Download the latest Matomo package: Navigate to your web directory and download:
    cd /var/www/html
    sudo wget https://builds.matomo.org/matomo-latest.zip and extract:
    sudo unzip matomo-latest.zip
  6. Set permissions: Assign ownership to www-data user:
    sudo chown -R www-data:www-data /var/www/html/matomo
  7. Create an Nginx server block: Use your preferred editor to create a config file:
    sudo nano /etc/nginx/sites-available/matomo and add:
    server { listen 80; server_name yourdomain.com www.yourdomain.com; root /var/www/html/matomo; index index.php; location / { try_files $uri /index.php?$args; } location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/var/run/php/php8.1-fpm.sock; } location ~ \.ht { deny all; } }

    Replace ‘yourdomain.com’ with your actual domain.

  8. Enable the site and restart Nginx: Run:
    sudo ln -s /etc/nginx/sites-available/matomo /etc/nginx/sites-enabled/
    sudo nginx -t (to test configuration)
    sudo systemctl restart nginx
  9. Configure SSL (recommended): Use Certbot to obtain a free SSL certificate:
    sudo apt install certbot python3-certbot-nginx
    sudo certbot --nginx -d yourdomain.com -d www.yourdomain.com and follow prompts to secure your site.
  10. Complete the Matomo setup: Visit Related
    How to Install Matomo Analytics with Nginx on Ubuntu 24.04
Scroll to top