Matomo (formerly Piwik) is an open-source web analytics platform that provides detailed reports on website traffic, user behavior, and more. It is a popular alternative to Google Analytics for users who want full control over their data. In this guide, we will walk you through the steps to install Matomo on Ubuntu 22.04. Whether you're hosting Matomo locally or on a Windows VPS UK, this tutorial will help you get Matomo up and running effectively.
Step 1: Update Your System
Before starting the installation, ensure that your Ubuntu 22.04 system is updated. Run the following commands to update and upgrade your system:
sudo apt update && sudo apt upgrade
This ensures that you have the latest software packages and security updates installed. Keeping your system updated is essential whether you're deploying Matomo locally or on a UK Windows VPS.
Step 2: Install LAMP Stack (Linux, Apache, MySQL, PHP)
Matomo requires a LAMP stack to function. You’ll need to install Apache, MySQL, and PHP. Run the following commands to install the LAMP stack:
sudo apt install apache2 mysql-server php libapache2-mod-php php-mysql php-cli php-xml php-mbstring php-curl php-zip php-gd
After the installation, enable the Apache and MySQL services:
sudo systemctl enable apache2
sudo systemctl enable mysql
sudo systemctl start apache2
sudo systemctl start mysql
This step sets up the necessary environment for running Matomo, whether you're hosting locally or on a VPS Windows Servers platform.
Step 3: Secure MySQL Installation
After installing MySQL, it’s important to secure the database. Run the following command to start the MySQL security script:
sudo mysql_secure_installation
Follow the prompts to secure your MySQL installation. This includes setting a root password, removing anonymous users, and disabling remote root logins. This step is important for securing your database, whether you're running Matomo on a local server or hosting it on a Windows VPS hosting UK.
Step 4: Create a Database for Matomo
Next, create a MySQL database and user for Matomo. Log in to the MySQL shell:
sudo mysql -u root -p
Create a new database and user for Matomo:
CREATE DATABASE matomo_db;
CREATE USER 'matomo_user'@'localhost' IDENTIFIED BY 'yourpassword';
GRANT ALL PRIVILEGES ON matomo_db.* TO 'matomo_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;
This creates a database for Matomo and grants the necessary privileges to the user. This configuration works whether you are setting up Matomo locally or on a Windows VPS Italy.
Step 5: Download and Install Matomo
Now, you need to download the latest version of Matomo from the official website. Navigate to your web directory:
cd /var/www/html
Download Matomo using wget
:
wget https://builds.matomo.org/matomo-latest.zip
Once downloaded, unzip the Matomo package:
sudo unzip matomo-latest.zip
Change the ownership of the Matomo directory to the Apache user:
sudo chown -R www-data:www-data /var/www/html/matomo
This will ensure that Apache can access the Matomo files, regardless of whether you're hosting locally or on a UK VPS Windows hosting solution.
Step 6: Configure Apache for Matomo
You now need to configure Apache to serve Matomo. Create a new virtual host file for Matomo:
sudo nano /etc/apache2/sites-available/matomo.conf
Add the following configuration, replacing your-domain.com
with your domain:
ServerAdmin admin@your-domain.com
DocumentRoot /var/www/html/matomo
ServerName your-domain.com
ServerAlias www.your-domain.com
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
Save and close the file. Enable the Matomo site and the Apache rewrite module:
sudo a2ensite matomo.conf
sudo a2enmod rewrite
sudo systemctl restart apache2
This configuration enables Matomo to run on your domain or IP address, whether you're deploying locally or on a Windows VPS hosting UK solution.
Step 7: Complete the Matomo Web Installer
With Apache configured, you can now complete the installation through the Matomo web interface. Open your browser and navigate to:
http://your-domain.com
Follow the on-screen instructions to complete the setup. You will need to enter your MySQL database information and set up an admin account for Matomo.
Once the setup is complete, Matomo will be ready to track and analyze your website traffic. This step is the same whether you're hosting locally or using a Windows Virtual Private Server hosting platform.
Step 8: Secure Your Matomo Installation with SSL
To ensure secure communication between your users and the server, it's important to enable SSL. You can use Let’s Encrypt to obtain a free SSL certificate. First, install Certbot:
sudo apt install certbot python3-certbot-apache
Then, run Certbot to obtain and configure the SSL certificate for your domain:
sudo certbot --apache -d your-domain.com
Follow the prompts to complete the setup. Certbot will automatically configure Apache to use the SSL certificate, ensuring secure access to your Matomo instance.