How to Self-Host Matomo on a VPS (Complete Guide)
Matomo is an open-source web analytics platform that gives you complete control over your data. Self-hosting Matomo on a Virtual Private Server (VPS) provides flexibility, performance, and privacy compared to third-party analytics solutions. This guide will walk you through the steps to self-host Matomo on a VPS, with an emphasis on installation methods and configuration.
Why Choose a VPS for Matomo?
Self-hosting Matomo on a VPS allows developers to customize their environment and ensures compliance with data privacy regulations. A VPS offers several benefits:
- Full control over the server environment.
- Ability to scale resources as needed.
- Enhanced security and privacy.
Hereโs a quick comparison of some top VPS providers, reflecting on cost and features:
| Provider | Starting Price | Features |
|---|---|---|
| Contabo VPS | 5.99 EUR/mo | High storage, good support |
| Hetzner Cloud | 4.15 EUR/mo | Flexible pricing, good performance |
| DigitalOcean | 6 USD/mo | Easy setup, developer-friendly tools |
| Vultr | 6 USD/mo | Global data centers, simple billing |
| Linode | 5 USD/mo | Consistent performance, robust API |
You can check out the full VPS comparison for more details.
Prerequisites
Before you start, ensure you have the following:
- A VPS with at least 1 GB of RAM and 20 GB of SSD storage.
- A domain name pointing to your VPS IP address (optional).
- Access to your VPS via SSH.
- Basic knowledge of Linux command line.
Providers like Contabo, Hetzner, and DigitalOcean are excellent choices.
Step 1: Setting Up the Environment
Log into your VPS using SSH:
ssh root@your_vps_ip
Update the package list and install necessary dependencies:
sudo apt update && sudo apt upgrade -y
sudo apt install apache2 mysql-server php php-mysql php-cli php-curl php-gd php-xml php-mbstring unzip -y
Step 2: Configuring the Database
Log into MySQL to create a new database and user:
sudo mysql -u root -p
Execute 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;
This sets up a database for Matomo, ensuring that you have a dedicated user.
Step 3: Downloading and Configuring Matomo
Now, download Matomo from the official site:
cd /var/www/html
wget https://builds.matomo.org/matomo-latest.zip
unzip matomo-latest.zip
rm matomo-latest.zip
Adjust permissions for the Matomo directory:
sudo chown -R www-data:www-data matomo
sudo chmod -R 755 matomo
Step 4: Setting Up Apache
Create a new Apache configuration file:
sudo nano /etc/apache2/sites-available/matomo.conf
Add the following configuration:
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot /var/www/html/matomo
ServerName yourdomain.com
<Directory /var/www/html/matomo>
Options FollowSymLinks
AllowOverride All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/matomo_error.log
CustomLog ${APACHE_LOG_DIR}/matomo_access.log combined
</VirtualHost>
Enable the new configuration and the rewrite module:
sudo a2ensite matomo.conf
sudo a2enmod rewrite
sudo systemctl restart apache2
Step 5: Completing Installation via Web Interface
Open your web browser and navigate to http://yourdomain.com. Follow the on-screen instructions to complete the installation. Youโll need to provide the database information created earlier:
- Database host:
localhost - Database user:
matomo_user - Database name:
matomo_db - Password:
your_password
After successful setup, you can log in to your Matomo dashboard.
Optional: Installing Matomo with Docker
If you prefer to use Docker for installation, hereโs a quick guide:
- Install Docker on your VPS:
sudo apt install docker.io -y
sudo systemctl start docker
sudo systemctl enable docker
- Pull the official Matomo Docker image:
docker pull matomo
- Run the Matomo container:
docker run -d --name matomo -e MATOMO_DB_HOST=db -e MATOMO_DB_USER=matomo_user -e MATOMO_DB_PASS=your_password -e MATOMO_DB_NAME=matomo_db -p 80:80 matomo
This will set up Matomo using Docker with minimal configuration.
FAQs
How much does it cost to self-host Matomo on a VPS?
The cost of self-hosting Matomo depends on the VPS provider you choose. Providers like Hetzner Cloud offer plans starting at 4.15 EUR/month, while others like Contabo start at 5.99 EUR/month. DigitalOcean and Vultr also provide competitive pricing at around 6 USD/month. Ensure that your plan has enough resources to handle your analytics needs.
What technical skills are required to install Matomo on a VPS?
To install Matomo, youโll need a basic understanding of Linux, familiarity with SSH, and knowledge of web server configurations. Understanding MySQL database management is also beneficial since youโll need to create a database for Matomo. For those unfamiliar with these concepts, numerous online resources, including r/selfhosted, can provide guidance.
Can I migrate from an external Matomo instance to my self-hosted version?
Yes, you can migrate your data from an external Matomo instance to your self-hosted version. Export your data from the existing Matomo instance and import it into your new setup. Refer to Matomoโs official documentation for detailed steps on backup and migration to ensure a smooth transition.
By following this guide, you can successfully self-host Matomo on a VPS and gain control over your web analytics.