Learn how to – Install Matomo (Piwik) Web Analytics on Ubuntu 22.04|20.04|18.04.
Matamo (formerly Piwik) is a free and open source web analytics application developed in PHP to be the ultimate alternative to Google Analytics, with full control over your data. Matomo can be used for a site with a few visits per day or websites that receive many millions of visits per day to track Key Performance Indicators such as visits, goal conversion rates, downloads, keywords, and many more.
Our previous related article was on the installation of Fathom website analytics tool on Ubuntu / CentOS / Debian Linux
Matamo gives you a detailed user-centric insight on website actions, both for the direct visits to the website or access through a mobile application. You can extend and customize the application using its API’s and detailed user documentation. Install Matomo today and get to learn about your users’ behavior – where they come from, what they are doing and where they are going.
See a full list of Matamo Dashboards
Install Matomo (Piwik) Web Analytics on Ubuntu 22.04|20.04|18.04
The installation of Matomo ( formerly Piwik) on Ubuntu is covered in this section. The process is straightforward and should be easy to follow.
To run Matomo (Piwik) your host server need to have a couple of things:
- A web server such as Apache, Nginx, IIS, etc.
- PHP version 5.5.9 or greater
- MySQL version 5.5 or greater, or MariaDB
- PHP extension pdo and pdo_mysql, or the mysqli extension.
Step 1: Install PHP with required Extensions
Run below commands to install PHP on your Ubuntu:
sudo apt update
sudo apt install unzip wget php php-fpm php-curl php-gd php-cli php-mysql php-xml php-mbstring
Step 2: Install MySQL / MariaDB Database Server
As mentioned earlier, Matomo needs a database server, which can be MySQL or MariaDB.
sudo apt install mariadb-server
After installing a database server, proceed to create a user used by Matomo
Login to MySQL shell as root user
sudo mysql -u root -p
Create a database and user with access privileges
CREATE DATABASE matomo;
GRANT ALL PRIVILEGES ON matomo.* TO 'matomo'@'localhost' IDENTIFIED BY "StrongPassword";
FLUSH PRIVILEGES;
quit
Step 3: Download Matomo / Piwik
Download the latest release of Matomo/Piwik using wget
wget https://builds.piwik.org/piwik.zip
Uncompress the package
unzip piwik.zip
Move piwik
directory to /var/www/
sudo mv piwik/ /var/www/matomo/
Step 4: Install Nginx and configure Nginx
Download and install nginx
sudo apt install nginx
Create nginx configuration file for Matomo
sudo vim /etc/nginx/conf.d/matomo.conf
Add the following contents:
server {
listen 80;
root /var/www/matomo;
index index.php index.html;
access_log /var/log/nginx/matomo_access.log;
error_log /var/log/nginx/matomo_error.log;
server_name stats.example.com www.stats.example.com;
client_max_body_size 100M;
location / {
try_files $uri /index.php?$query_string;
}
location ~ .php$ {
include /etc/nginx/fastcgi_params;
fastcgi_pass unix:/var/run/php/php-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
Change server_name and fastcgi_pass values to match your correct settings.
Change Matomo directory ownership
sudo chown -R www-data:www-data /var/www/matomo/
Start nginx and ensure it is set to start on boot
sudo systemctl restart nginx
sudo systemctl enable nginx
Step 5: Setup Matomo / Piwik
Access Setup web page by opening the link http://stats.example.com on your browser. You should be greeted with a welcome page. Click “Next”
Ensure all system checks are passed, then click the “Next” button
You should get to the Database Setup page. Use database credentials configured earlier
- Database Server : 127.0.0.1
- Login: matomo
- Password: <StrongPassword>
- Database Name: matomo
- Adapter: PDO/MYSQL
Creation of the Tables should return a success.
Next, you have to create a Super User. Provide username, password and email address.
Setup a Website by providing:
- Website name
- Website URL
- Website time zone
- Enable/Disable Ecommerce
Copy and save generated JavaScript Tracking Code. A login page should appear, provide username and password to get in.
If you want to do more than track page views, please check out the Matomo Javascript Tracking documentation for the list of available functions. Using these functions you can track goals, custom variables, e-commerce orders, abandoned carts and more.
Leave a Reply
You must be logged in to post a comment.