Mets Minor League Blog

Music theory, instruments and musicians

Mets Minor League Blog

Music theory, instruments and musicians

How to Install Matomo Analytics with Apache on Ubuntu 24.04

How to Install Matomo Analytics with Apache on Ubuntu 24.04

Implementing a robust analytics solution is crucial for understanding your website visitors and optimizing your online presence. Matomo Analytics is a powerful, open-source alternative to proprietary tools like Google Analytics, offering full control over your data. Installing Matomo on an Ubuntu 24.04 server with Apache ensures a secure, customizable, and scalable setup. This step-by-step guide walks you through the process, from initial requirements to troubleshooting common issues, so you can successfully deploy Matomo on your server.

What You’ll Need

  • Ubuntu 24.04 server with root or sudo access
  • Domain name pointed to your server’s IP address
  • Basic knowledge of Linux command line
  • Apache web server installed and running
  • MySQL or MariaDB database server installed
  • PHP 7.4 or higher with required modules (see prerequisites)
  • SSL certificate for HTTPS (recommended but optional)

Step-by-Step

  1. Update your system packages: Run sudo apt update && sudo apt upgrade -y to ensure all packages are current.
  2. Install necessary dependencies: Install Apache, MariaDB, PHP, and required PHP modules:
    sudo apt install apache2 mariadb-server php php-mysql php-gd php-xml php-mbstring php-curl php-zip php-bcmath unzip -y
  3. Secure your MariaDB installation: Run sudo mysql_secure_installation and follow prompts to set root password and secure your database server.
  4. Create a database and user for Matomo: Log into MySQL with sudo mysql -u root -p and execute:
    CREATE DATABASE matomo_db CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
    CREATE USER 'matomo_user'@'localhost' IDENTIFIED BY 'StrongPasswordHere';
    GRANT ALL PRIVILEGES ON matomo_db.* TO 'matomo_user'@'localhost';
    FLUSH PRIVILEGES;
    EXIT;
  5. Download the latest Matomo package: Navigate to a directory of your choice and run:
    wget https://builds.matomo.org/matomo-latest.zip
  6. Extract and move the files: Unzip the package and move it to your web root:
    unzip matomo-latest.zip
    sudo mv matomo /var/www/html/matomo
  7. Set correct permissions: Ensure Apache can access the files:
    sudo chown -R www-data:www-data /var/www/html/matomo
    sudo chmod -R 755 /var/www/html/matomo
  8. Create an Apache virtual host: Create a configuration file at /etc/apache2/sites-available/matomo.conf with 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>

    Then enable the site and rewrite module:

    sudo a2ensite matomo.conf
    sudo a2enmod rewrite
    sudo systemctl restart apache2
  9. Configure HTTPS (optional but recommended): Obtain an SSL certificate via Certbot or other methods, then update your virtual host to listen on port 443 with SSL settings.
  10. Complete the web installer: Open your browser and navigate to http://yourdomain.com. Follow the on-screen prompts, entering your database details, creating an admin account, and configuring basic settings. This setup will finalize the installation.
  11. Secure your installation: Remove the installer files if prompted, and ensure your server uses HTTPS to encrypt data transmission.

Common Mistakes

  • Not setting correct permissions on the Matomo directory, leading to access errors.
  • Forgetting to enable Apache rewrite module, which prevents clean URLs and proper functioning.
  • Using an insecure database password or not securing your database user.
  • Failing to update your server packages before starting, resulting in compatibility issues.
  • Neglecting to configure SSL, which exposes data to potential interception.

Tips

  • Always backup your database before major updates or changes.
  • Use strong, unique passwords for database users and admin accounts.
  • Configure automatic updates for your Ubuntu server to keep security patches current.
  • Enable HTTPS to protect user data and improve SEO rankings.
  • Regularly check Apache logs for errors or suspicious activity.

Troubleshooting

If you encounter issues during installation or access, consider these steps:

  • Verify Apache is running: sudo systemctl status apache2.
  • Check Apache error logs: sudo tail -f /var/log/apache2/error.log.
  • Ensure your domain points correctly to your server IP and DNS has propagated.
  • Confirm database credentials are correct and that the database user has appropriate permissions.
  • Clear your browser cache or try accessing via incognito mode to rule out caching issues.
  • If the installer page doesn’t load, check your firewall settings to ensure ports 80 and 443 are open.

Frequently Asked Questions

1. Can I install Matomo without SSL?

Yes, but it’s highly recommended to enable SSL to secure data transmission, especially if you handle sensitive information or user data.

2. How often should I update Matomo?

Regularly check for updates within the Matomo admin panel or via their website. Keeping software up-to-date ensures security and access to new features.

3. Is it necessary to install a firewall?

Yes, configuring a firewall like ufw helps protect your server from unauthorized access and attacks. Allow only necessary ports like 80, 443, and SSH.

4. Can I host multiple websites with this setup?

Yes, by creating separate virtual host configurations for each domain, you can host multiple sites on the same server.

5. How do I back up my Matomo data?

Regularly back up your database and the Matomo directory. Use database dump commands and copy the files to a secure location.

6. What are the resource requirements for Matomo?

Depends on your traffic, but generally, a modest server with 2-4 CPU cores, 4GB RAM, and sufficient disk space suffices for small to medium sites.

By following this guide carefully, you can successfully deploy Matomo Analytics on Ubuntu 24.04 with Apache, giving you full control over your website analytics and data privacy. Remember to keep your system secure and maintain regular backups to ensure smooth operation.

Related

How to Install Matomo Analytics with Apache on Ubuntu 24.04
Scroll to top