Installing Matomo (Piwik) for Web and Mobile Data Analytics on Alibaba Cloud ECS

Prerequisites

  1. Alibaba Cloud ECS instance with Ubuntu 16.04 64-bit installed.
  2. Firewall or Security group rules configured to allow ports 80, and 443.
  3. A domain name that needs to be pointed towards your ECS instance.
apt update && apt -y upgrade && apt -y autoremove

Install NGINX with PHP 7

apt -y install software-properties-common
add-apt-repository ppa:ondrej/php –yes
apt update
apt -y install nginx php7.2 php7.2-curl php7.2-gd php7.2-cli php7.2-mysql php-xml php7.2-mbstring php7.2-fpm unzip
nano /etc/php/7.2/fpm/php.ini
memory_limit = 512M    
...
date.timezone =Asia/Kolkata
...
cgi.fix_pathinfo=0
systemctl restart php7.2-fpm
systemctl enable php7.2-fpm
systemctl restart nginx
systemctl enable nginx

Download Matomo

wget https://builds.matomo.org/piwik.zip
unzip piwik.zip -d /var/www/
chown -R www-data:www-data /var/www/

Setup SSL

add-apt-repository ppa:certbot/certbot –yes
apt update
apt -y install certbot
certbot certonly --webroot -w /var/www/html -d matomo.example.com
{ crontab -l; echo '36 2   * /usr/bin/certbot renew --post-hook "systemctl reload nginx"'; } | crontab -
nano /etc/nginx/sites-available/matomo
server {
listen 80;
server_name matomo.example.com;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl;
server_name matomo.example.com;

ssl_certificate /etc/letsencrypt/live/matomo.example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/matomo.example.com/privkey.pem;

add_header Strict-Transport-Security "max-age=15768000;
includeSubDomains; preload;";
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block";
add_header X-Robots-Tag none;
add_header X-Download-Options noopen;
add_header X-Permitted-Cross-Domain-Policies none;

root /var/www/piwik/;
index index.php;
access_log /var/log/nginx/matomo.example.com_access.log;
error_log /var/log/nginx/matomo.example.com_error.log;
gzip on;
gzip_vary on;
gzip_comp_level 4;
gzip_min_length 256;
gzip_proxied expired no-cache no-store private no_last_modified no_etag auth;
gzip_types application/atom+xml application/javascript application/json application/ld+json application/manifest+json application/rss+xml application/vnd.geo+json application/vnd.ms-fontobject application/x-font-ttf application/x-web-app-manifest+json application/xhtml+xml application/xml font/opentype image/bmp image/svg+xml image/x-icon text/cache-manifest text/css text/plain text/vcard text/vnd.rim.location.xloc text/vtt text/x-component text/x-cross-domain-policy;
location = /index.php {
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_buffers 256 4k;
fastcgi_intercept_errors on;
fastcgi_read_timeout 14400;
fastcgi_index index.php;
}
location = /piwik.php {
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_buffers 256 4k;
fastcgi_intercept_errors on;
fastcgi_read_timeout 14400;
fastcgi_index index.php;
}
location ~* ^.+\.php$ {
return 403;
}
location ~* (?:DESIGN|(?:gpl|README|LICENSE)[^.]*|LEGALNOTICE)(?:\.txt)*$ {
return 302 /;
}
location ~* \.(?:bat|git|ini|sh|svn[^.]*|txt|tpl|xml)$ {
return 404;
}
location ~ ^/(config|core|lang|misc|tmp)/ {
deny all;
}
}
ln -s /etc/nginx/sites-available/matomo /etc/nginx/sites-enabled/matomo
systemctl restart nginx php7.2-fpm

Setting Up MySQL Database on ApsaraDB RDS instance

Web-based Installation

Adding Matomo Tracking Code in WordPress

Using WP-Matomo

Adding Tracking Code Manually

--

--

--

Follow me to keep abreast with the latest technology news, industry insights, and developer trends. Alibaba Cloud website:https://www.alibabacloud.com

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Building an RSS Microservice with Deno and Graph QL

Wabbit-tech — Sharetribe installation on Ubuntu 18.04

Merge Sort Algorithm

PL/SQL Developer usage skills and shortcut keys

Why Software Prototyping is the Key to Seamless App Development

Concurrent Sudoku Solver: Part 2 - Using Cats Effect Ref + Deferred + IO.race

Band Protocol June 2020 Community Update

How to Connect China and the World Using CEN

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Alibaba Cloud

Alibaba Cloud

Follow me to keep abreast with the latest technology news, industry insights, and developer trends. Alibaba Cloud website:https://www.alibabacloud.com

More from Medium

Load data from Google sheet to AWS RDS using Fivetran

Using Google Cloud Data Fusion APIs to get Pipeline Run Times and Metrics

Migrating Data from PostgreSQL to Amazon Redshift via AWS DMS

Why Get a Cloud Certificate in Data Engineering?