Piwik

How to Install Piwik on Ubuntu 24.04: A Comprehensive Guide

Welcome back to the Greenhost.cloud blog, where we empower you with the knowledge to manage your web hosting needs effectively. Today, we’re diving into a powerful tool for web analytics: Matomo, formerly known as Piwik. This open-source platform is a great alternative to Google Analytics, giving you full control over your data while offering robust features for tracking and analyzing your website traffic.

In this guide, we’ll walk you through the steps to install Matomo on Ubuntu 24.04. Let’s get started!

Prerequisites

Before we begin, ensure you have the following:

  1. A server running Ubuntu 24.04: Ensure your system is up to date.
  2. Root access: You’ll need to run commands as a superuser.
  3. LAMP Stack: Ensure you have Apache, MySQL, and PHP installed on your server. If you haven’t set this up, you can do so with the following commands:
   sudo apt update
   sudo apt install apache2 mysql-server php php-mysql libapache2-mod-php php-xml php-mbstring
  1. Composer: This is a dependency manager for PHP. You can install it with:
   sudo apt install curl
   curl -sS https://getcomposer.org/installer | php
   sudo mv composer.phar /usr/local/bin/composer
  1. An FTP client: To upload files to your server if needed.

Step 1: Download Matomo

First, we’ll download the latest version of Matomo. Visit the Matomo download page to get the latest version link, or use the following command to download it directly to your server.

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

After downloading, unzip the file:

sudo apt install unzip
sudo unzip matomo-latest.zip
sudo mv matomo/* .

Then, remove the zip file:

sudo rm matomo-latest.zip

Step 2: Set Up Permissions

Next, we need to set the correct permissions for the Matomo files. This ensures that the web server can read and write to necessary directories.

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

Step 3: Create a Database for Matomo

Now, let’s create a MySQL database for Matomo. Log into MySQL:

sudo mysql -u root -p

Once in the MySQL shell, run the following commands:

CREATE DATABASE matomo_db;
CREATE USER 'matomo_user'@'localhost' IDENTIFIED BY 'your_password';
GRANT ALL PRIVILEGES ON matomo_db.* TO 'matomo_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;

Make sure to replace 'your_password' with a strong password.

Step 4: Configure Apache

To serve Matomo, we need to create an Apache configuration file. Create a new configuration file:

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

Add the following configuration:

<VirtualHost *:80>
    ServerAdmin [email protected]
    DocumentRoot /var/www/html
    ServerName yourdomain.com
    <Directory /var/www/html>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Require all granted
    </Directory>
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Replace yourdomain.com with your actual domain name. Save and exit the editor.

Now, enable the new site and rewrite module:

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

Step 5: Run the Matomo Installation Wizard

Open your web browser and navigate to your server’s IP address or domain name:

http://yourdomain.com

You should be greeted by the Matomo installation wizard. Follow the on-screen instructions:

  1. System Check: Ensure all requirements are met.
  2. Database Setup: Input the database name, username, and password you created earlier.
  3. Setup Super User: Create an admin account.
  4. Configure Matomo: Set up your website and tracking options.

Step 6: Complete the Installation

After completing the setup, Matomo will provide you with a tracking code. Add it to your website to start collecting data.

Conclusion

Congratulations! You have successfully installed Matomo on your Ubuntu 24.04 server. With Matomo, you have full control over your analytics data, ensuring privacy and security.

If you have any questions or run into issues during the installation process, feel free to leave a comment below or reach out to our support team. Happy tracking!


For more tutorials and tips, stay tuned to the Greenhost.cloud blog!