blog-image

Aug 02, 2018

13 min read

Matomo: How to install self-hosted analytics on your VPS

Written by

Vippy The VPS
Matomo (formerly Piwik) is an open source analytics platform currently used by many individuals, companies, and governments all over the world. In this tutorial, we’ll cover how you install Matomo as a self-hosted alternative on your Ubuntu 16.04 VPS—perfect for those who don’t want to pass on your website’s, or your user’s, data onto a third-party solution like Google Analytics. Matomo is so feature-rich that it’s hard to list them all, so let’s get right into it.

Prerequisites

  • A VPS running Ubuntu 18.04.
  • A non-root, sudo-enabled user. If you only have a root user, see our SSH tutorial for details on creating new users.
  • A registered domain name.
  • A DNS A record that points to your server’s IP address based on the FQDN you want to use. For example, an A record named test would point to test.DOMAIN.TLD.

Notes

  • This tutorial requires the use of domain names. Whenever you see either the SUBDOMAIN, DOMAIN, or TLD variables, replace them with the details of your domain name. In example.ssdnodes.com, example is the SUBDOMAIN, ssdnodes is the DOMAIN, and .com is the TLD.
  • This tutorial requires the use of passwords. Whenever you see the PASSWORD variable, then replace it with your own.
[cta_inline]

Step 1. Install LAMP or LEMP

Matomo is a PHP-based web application, so you need to have either a LAMP (Apache) or LEMP (Nginx) stack installed. If you don’t have one already, follow the proceeding steps; if you do have a LAMP/LEMP stack installed, you can skip ahead to Step 2.

Install Apache or Nginx

You can choose either Apache or Nginx as a web server to host Matomo. If you opt for Apache then install it with the steps described below, otherwise, skip the following steps and proceed with installing Nginx in the subsequent steps.
$ sudo apt-get install apache2
$ sudo systemctl enable apache2.service
$ sudo systemctl start apache2.service
Alternately, you can choose Nginx as a web server. Just issue the following commands to install and enable it during system boot.
$ sudo apt-get install nginx
$ sudo systemctl enable nginx.service
$ sudo systemctl start nginx.service
Once you have done with installing one of the above web servers, visit http://SUBDOMAIN.DOMAIN.TLD to confirm that everything is working smoothly.

Install MariaDB

The next step of configuring a LAMP/LEMP stack is to install MySQL server. Issue the following commands from the terminal to install it, and optionally, you can run mysql_secure_installation to make it secure.
$ sudo apt-get install mariadb-server
$ sudo systemctl enable mariadb.service
$ sudo mysql_secure_installation
The default password for root user is blank. To update the password of the root user, get the MySQL prompt and update the password by issuing the following command from the MySQL shell.
$ mysql -u root -p
MariaDB [mysql]> update user SET PASSWORD=PASSWORD("PASSWORD") WHERE USER='root';

Install PHP

In the final step of configuring LAMP/LEMP server, install PHP and its various extensions needed by Matomo. Use the following apt-get command to install these PHP extensions.
$ sudo apt-get install php7.2 php7.2-common php7.2-mbstring php7.2-xmlrpc php7.2-soap php7.2-mysql php7.2-gd php7.2-xml php7.2-cli php7.2-zip
Apart from above php extensions, Matomo also needs a web server that can process PHP pages. You need to install appropriate PHP modules depending on which web server you
Continue reading this article
by subscribing to our newsletter.
Subscribe now

A note about tutorials: We encourage our users to try out tutorials, but they aren't fully supported by our team—we can't always provide support when things go wrong. Be sure to check which OS and version it was tested with before you proceed.

If you want a fully managed experience, with dedicated support for any application you might want to run, contact us for more information.