Guides 11792 Published by

The post takes you step‑by‑step through setting up Matomo on Debian 11, starting with installing Apache, PHP and MySQL drivers, then creating a dedicated database user and fine‑tuning PHP limits to handle large analytics imports. It explains why each prerequisite matters—missing packages will trigger installer errors and an isolated database keeps your tracking data safe from accidental leaks. After downloading the latest Matomo archive, the guide shows how to adjust file ownership for Apache’s www‑data user, run the web wizard with the correct credentials, and harden the installation by disabling directory listing and encouraging HTTPS use. Finally, it reminds readers that keeping the codebase up‑to‑date via Git pulls brings performance fixes and new features, while offering troubleshooting tips such as checking virtual host configs or error logs if anything goes wrong.



Monitor Your Server Like a Pro—Install Matomo on Debian 11

If you’re tired of guessing how your site’s traffic behaves, installing Matomo on Debian 11 gives you full control over analytics data right where it belongs: on your own server.

You’ll learn how to pull the latest release, set up a dedicated database user, and tweak PHP so that your metrics don’t lag or crash.

1. Install prerequisites
sudo apt update && sudo apt install -y apache2 php libapache2-mod-php php-mysql unzip wget git

Debian ships with a very lean PHP stack. Matomo needs MySQL, the MySQL PHP extension, and Apache’s mod_php to run out of the box. Skipping any of these will make the installer scream errors.

2. Create a MySQL user for Matomo
sudo mysql -u root -p
CREATE DATABASE matomo CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
GRANT ALL PRIVILEGES ON matomo.* TO 'matomo_user'@'localhost' IDENTIFIED BY 'StrongPassword123';
FLUSH PRIVILEGES;
EXIT;

Matomo stores every hit in its own database. Giving it a dedicated user keeps your data isolated and prevents accidental privilege leaks.

3. Tune PHP for analytics

Edit /etc/php/8.1/apache2/php.ini (adjust the version if you’re on 7.4 or 8.0):

memory_limit = 512M
max_execution_time = 300
post_max_size = 200M
upload_max_filesize = 200M

Matomo can chew through a lot of data in a single request, especially during imports. The larger memory and time limits stop PHP from bailing out mid‑process.

4. Pull down and unpack Matomo
cd /var/www/html
sudo wget https://builds.matomo.org/matomo-latest.zip
sudo unzip matomo-latest.zip
sudo chown -R www-data:www-data matomo

www-data is the user Apache runs as. If you don’t set ownership correctly, the web installer will refuse to write its config files.

5. Run the installer script

Open a browser and navigate to http://your‑server-ip/matomo. The wizard will ask for:

  • Database host: localhost
  • Database name: matomo
  • User: matomo_user
  • Password: StrongPassword123

Then pick an admin account (yes, you’ll need a password that isn’t “admin”). Finish the setup and you’re good.

6. Harden your Matomo installation
# Disable directory listing for the matomo folder
sudo mkdir /etc/apache2/conf-available/matomo.conf
echo '<Directory /var/www/html/matomo>' | sudo tee -a /etc/apache2/conf-available/matomo.conf
echo '  Options -Indexes' | sudo tee -a /etc/apache2/conf-available/matomo.conf
echo '</Directory>' | sudo tee -a /etc/apache2/conf-available/matomo.conf
sudo a2enconf matomo
sudo systemctl reload apache2

# Force HTTPS (if you have certs in place)

Analytics data can be sensitive. Disabling directory listing prevents curious eyes from seeing raw files, and forcing HTTPS keeps your hits encrypted.

7. Keep it fresh
cd /var/www/html/matomo
sudo git init
sudo git remote add origin https://github.com/matomo-org/matomo.git
sudo git fetch --depth=1
sudo git reset --hard origin/master

Matomo’s features improve constantly. Pulling the latest code avoids missing out on performance fixes or new tags.

That’s all there is to it. You’ve got a self‑hosted analytics engine that won’t leak data to third‑party services and will stay up as long as your Debian machine does. If you run into hiccups, remember: check apache2ctl -S for virtual host issues, look at /var/log/apache2/error.log, and don’t be afraid to ping the Matomo community—they’re surprisingly helpful when you ask in plain English.

Cheers, and may your metrics stay smooth.