Install Matomo - Self-Hosted Google Analytics Alternative - on Linux 🌱

What is Matomo?

Matomo is the ethical alternative where you won't make privacy sacrifices or compromise your site. Matomo's the Google Analytics alternative that protects your data and your customer's privacy. A powerful web analytics platform with 100% data ownership. - https://matomo.org

Installing Matomo

  1. Log into the Debian device
  2. Run the following commands in a terminal:
    # update software repositories
    sudo apt update
    # install available updates
    sudo apt upgrade -y
    # install Apache HTTPD and MySQL
    sudo apt install apache2 mariadb-server mariadb-client -y
    # install PHP components
    sudo apt install php php-curl php-gd php-cli php-mysql php-xml php-mbstring -y
    # configure the MySQL database
    sudo su
    mysql_secure_installation
  3. Press Enter to login as root
  4. Type Y and press Enter to set a root password, type the password twice to confirm
  5. Type Y and press Enter to remove anonymous users
  6. Type Y and press Enter to disallow root login remotely
  7. Type Y and press Enter to remove the test database
  8. Type Y and press Enter to reload privilege tables
  9. Run the following command to login into MySQL:
    mysql -u root -p
  10. Authenticate with the root password set earlier
  11. Run the following commands to create the Matomo database and database user
    CREATE DATABASE analytics;
    GRANT ALL ON analytics.* to 'analytics'@'localhost' IDENTIFIED BY 'An@lyt1c$!';
    FLUSH PRIVILEGES;
    EXIT;
    exit
  12. Continue with the following commands to download and extract Matomo in the Apache webroot
    # download latest matomo build
    wget https://builds.matomo.org/matomo.zip
    # extract downloaded zip
    sudo unzip matomo.zip -d /var/www/html
    # move to webroot
    sudo mv /var/www/html/matomo /var/www/html/analytics
    # set the owner of the new analytics directory to www-data
    sudo chown -R www-data:www-data /var/www/html/analytics
  13. Open a web browser and navigate to http://DNSorIP/analytics
  14. Click the Next button on the Welcome screen
  15. Click the Next button on the System Check screen
  16. Fill in the database connection form as follows and click the Next button

    Database Server: 127.0.0.1
    Login: analytics
    Password: An@lyt1c$!
    Database Name: analytics
    Table Prefix:
    Adapter: MySQLI

  17. Click the Next button
  18. Create an administrative logon and set the password > Click the Next button
  19. Complete the form to add the first website to collect analytics on > Click the Next button
  20. Copy the generated code into the header of the application to monitor
  21. Click Next > Click Next on the Congratulations page
  22. Login with the admin logon created earlier
  23. Welcome to free self-hosted web analytics

Installing Dark Theme (Optional)

  1. Click the gear icon in the top right
  2. Select Platform > Marketplace from the left navigation menu
  3. Change the Show dropdown to Themes and search for Dark Theme
  4. Find Dark Theme and click the Install button
  5. Type the admin password to confirm the installation
  6. Click the Activate Theme button

Source: https://matomo.org/docs/installation/#getting-started