
How to Install Matomo Analytics on Ubuntu 20.04
Introduction
Matomo is an open-source, self-hosted web analytics application written in PHP. In this tutorial, you will learn how to install Matomo and a MariaDB database using Docker Compose, configure Nginx as a reverse proxy, and enable secure HTTPS connections with Certbot.
Prerequisites
Before you proceed with the installation, ensure that you have the following:
- An Ubuntu 20.04 server with UFW firewall enabled.
- Docker installed. Refer to the installation guide on how to set this up.
- Docker Compose installed. Follow the appropriate steps for installation.
- A domain name pointed at your server’s public IP address.
Note: You can skip the prerequisite steps if you are using a preconfigured Docker image.
Main Steps
Step 1 — Running Matomo and MariaDB with Docker Compose
The first step involves creating the Docker Compose configuration to launch the Matomo app and MariaDB database.
Start by creating a directory for your Matomo setup. You can use your home directory or any other preferred directory:
cd ~
mkdir matomo
cd matomo
Next, create a new file named docker-compose.yml:
nano docker-compose.yml
Paste the following configuration into the file:
version: "3"
services:
db:
image: mariadb
command: --max-allowed-packet=64MB
restart: always
environment:
- MARIADB_DATABASE=matomo
- MARIADB_USER
- MARIADB_PASSWORD
- MARIADB_ROOT_PASSWORD
volumes:
- ./db:/var/lib/mysql
app:
image: matomo
restart: always
volumes:
- ./matomo:/var/www/html
ports:
- 127.0.0.1:8080:80
This configuration defines two services: one for the MariaDB container and one for the Matomo application.
Save and exit the editor. In nano, use CTRL+O to save, then CTRL+X to exit.
Step 2 — Set Environment Variables
You need to set the environment variables for the MariaDB user, password, and root password. To do this, you can modify the docker-compose.yml file to include values for MARIADB_USER, MARIADB_PASSWORD, and MARIADB_ROOT_PASSWORD.
environment:
- MARIADB_DATABASE=matomo
- MARIADB_USER=your_user
- MARIADB_PASSWORD=your_password
- MARIADB_ROOT_PASSWORD=root_password
Replace your_user, your_password, and root_password with your desired values.
Step 3 — Start Docker Containers
After saving the configuration, run the following command to start your containers:
docker-compose up -d
Ensure that everything is running smoothly with:
docker-compose ps
Step 4 — Install and Configure Nginx
To serve your Matomo application, you will need to install Nginx. Use this command to install Nginx:
sudo apt update
sudo apt install nginx
Once installed, create a new server block configuration file for Matomo:
sudo nano /etc/nginx/sites-available/matomo
Input the following configuration:
server {
listen 80;
server_name example.com; # Replace with your domain name
location / {
proxy_pass http://127.0.0.1:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
Enable the configuration by creating a symbolic link to the sites-enabled directory:
sudo ln -s /etc/nginx/sites-available/matomo /etc/nginx/sites-enabled/
Test the Nginx configuration for syntax errors:
sudo nginx -t
Restart Nginx to apply the changes:
sudo systemctl restart nginx
Step 5 — Enable HTTPS with Certbot
To secure your Matomo installation, you must obtain an SSL certificate. Install Certbot:
sudo apt install certbot python3-certbot-nginx
Run the following command to obtain and automatically configure SSL certificates:
sudo certbot --nginx -d example.com
Follow the prompts to complete the SSL setup, ensuring you agree to the terms of service and provide an email for renewal notifications.
Advanced Configuration
Once you have successfully installed Matomo, you may want to make additional configurations:
- Database Optimization: Tune the MariaDB settings for better performance based on your website traffic.
- Matomo Plugins: Explore the Matomo marketplace to add plugins that enhance your tracking capabilities.
- Privacy Settings: Configure the privacy settings to comply with GDPR or other regulations.
Best Practices
To ensure a smooth experience with Matomo, consider the following best practices:
- Regularly update Matomo and its plugins to maintain security.
- Backup your database and configurations frequently to avoid data loss.
- Monitor server resource usage to adjust configurations as needed.
Troubleshooting
If you encounter issues, here are a few common troubleshooting steps:
- Check Docker container logs for error messages:
docker-compose logs
- Verify Nginx configuration syntax and restart the service:
sudo nginx -t
sudo systemctl restart nginx
- Ensure that the firewall allows traffic on relevant ports:
sudo ufw allow 'Nginx Full'
Conclusion
You have successfully installed Matomo Analytics on your Ubuntu 20.04 server using Docker Compose. This guide covered the entire process from installation to configuration, ensuring a secure and efficient web analytics solution. By following best practices and regularly updating your system, you can leverage Matomo’s powerful features for insightful data analysis.
Konsultasi Jasa Setup SekarangFor further assistance or advanced setup, consider consulting a professional service.
Verifikasi Teknis
Panduan ini disusun berdasarkan referensi teknis terbaru. Namun, konfigurasi server dapat bervariasi. Lihat sumber referensi asli →
