Self-hosting Matomo gives you privacy-first, powerful analytics. Below are the complete steps, from installation to integrating the tracker into your Hugo static site.
Table of Contents
1. Download Matomo On-Premise
- Visit the Matomo On-Premise download page and download the latest .zip file.
2. Unzip and Upload Matomo
Unzip the file, creating a matomo folder.
Upload all files to your web server. This can be a subfolder (example: mydomain.com/analytics) or a subdomain, such as stats.mydomain.com. Use FTP/SFTP or your web host’s file manager to upload.
Alternatively, upload and extract via command line.
wget https://builds.matomo.org/matomo.zip && unzip matomo.zip
Set correct file permissions and ownership according to your server.
3. Create a MySQL Database
- Use your host’s control panel or command line to create a new database for Matomo.
- Create a dedicated user with a strong password and assign it to the new database for security.
4. Access and Start the Web Installer
- In your browser, go to the URL where you installed Matomo (e.g., https://stats.mydomain.com).
- The setup wizard will launch, running checks for server requirements.
- Click Next to proceed through the setup steps.
5. Configure the Database and Super Admin
- Fill in the database details you created: host, database name, username, password, and port if not default.
- Matomo will create its tables. Wait for a success message.
- Next, create your Matomo super user account (username, email, strong password).
- Continue to follow wizard steps for general configuration.
6. Add Your First Website
- The wizard prompts you to add your first tracked site:
- Set the website name, URL, and timezone.
- The Javascript Tracking Code is generated for this site.
7. Insert Matomo Tracking Code into Hugo
Copy the presented tracking snippet.
In your Hugo project, locate or create the file:
layouts/partials/head.html
Paste the tracking code inside the <head> section for all pages.
If your theme uses different partials (e.g., meta.html), follow the same copy/override method.
Tip: Only insert for production builds using Hugo’s hugo.Environment if desired.
8. Validate Tracking
- Deploy your Hugo site.
- Visit tracked pages; check the Matomo dashboard “Real-time” widget for activity, or use browser developer tools to confirm hits to matomo.php.
9. Secure Your Installation
- Set up two-factor authentication (2FA) for your Matomo admin user.
- Optionally, restrict file permissions further.
- For significant traffic sites, configure cron for auto-archiving reports to keep your dashboard fast.
10. Consider Additional Best Practices
- Secure your Matomo site with HTTPS.
- Regularly update Matomo for security and features.
- Review GDPR/data privacy requirements for your region.
- Customize tracking as needed using the Tag Manager or advanced settings.
Common Issues or Extra Steps
- System Requirements: Make sure PHP, MySQL/MariaDB, and required PHP extensions are present on your server.
- Firewall/DNS: Point your subdomain to the correct IP and open necessary ports.
- Permissions: After installation, restrict permissions on sensitive files (config folder).
- Multiple Sites: One Matomo install can track many sites—use the admin panel to add more.
By following these steps, you’ll have a fully functional, privacy-respecting analytics system with Matomo integrated into your Hugo site.