Content Linux Matomo Ubuntu Ubuntu Server Web Analytics

Install Matomo Web Analytics (Piwik) on Ubuntu 18.04 with Apache/Nginx

matomo install ubuntu

This tutorial can be displaying you methods to set up Matomo net analytics (previously generally known as Piwik) on Ubuntu 18.04 with Apache or Nginx net server. Matomo is an open-source various to Google analytics, which is probably the most widely-used net analytics software program.

What’s Web Analytics?

Web analytics software program are utilized by web sites to know what number of guests are on a website in a day/week/month, what net browser they’re utilizing, and so forth. It’s a essential piece of software program to assist develop their web sites. Google analytics is nice, however the knowledge of web site guests are saved on Google’s server. In the event you don’t need to share your web site guests’ knowledge to a 3rd celebration, you possibly can run your personal net analytics. They’re many self-hosted options to Google analytics and Matomo is a superb one.

Matomo Options

The open-source (GPL v3+ licensed) self-hosted Matomo version can present the next studies.

  • Prime key phrases and serps, web sites, social media web sites.
  • Prime web page URLs, web page titles, consumer nations, suppliers, working system, browser marketshare, display decision, desktop VS cellular,
  • Engagement (time on website, pages per go to, repeated visits),
  • Prime campaigns, customized variables, prime entry/exit pages, downloaded information, and lots of extra,
  • Categorised into 4 fundamental analytics report classes – Guests, Actions, Referrers, Objectives/Ecommerce (30+ reviews).
  • Statistics E-mail stories.
  • Web server log analytics.
  • And extra.

For a full record of options, please verify the Matomo options web page.

Self-hosted Matomo advantages

  • Full management of knowledge. Knowledge is saved on your server solely and you may select which nation the server is situated.
  • No knowledge limits. You’ll be able to maintain as many knowledge as your server can.
  • Absolutely customisable and extensible.

The cloud hosted Matomo has additional options, however you’ll be able to set up premium plugin on your self-hosted occasion to realize the identical performance.

Conditions of Putting in Matomo Web Analytics (Piwik) on Ubuntu 18.04

To comply with this tutorial, you will want a website identify and a server. I registered my area identify at NameCheap as a result of the worth is low they usually give whois privateness safety free for all times. A server with 512MB RAM is sufficient to run Matomo and listed here are the internet hosting suppliers that I like to recommend. I’ve used all of them.

  • Vultr (Begin at $2.5/month. Bank card required)
  • DigitalOcean (Begin at $5/month. No bank card is required. You should use Paypal).
  • Linode (Begin at $5/month. Bank card required)

Upon getting a server, set up Ubuntu on them and comply with the directions under.

Matomo is written in PHP and makes use of MySQL/MariaDB database. To comply with this tutorial, it’s assumed that you’ve already arrange LAMP or LEMP stack on Ubuntu 18.04. If not, please take a look at one of many following tutorial:

When you’re completed establishing LAMP or LEMP stack, come again right here and skim on.

Step 1: Obtain Matomo on Ubuntu 18.04

Log in to your server by way of SSH. You possibly can all the time use the next command to obtain the newest model of Matomo on your server. On the time of this writing, the newest model if Matomo three.7, which comes with a brand new function – tag supervisor. It’s one of many largest milestones for Matomo in the previous few years.

wget https://builds.matomo.org/matomo-latest.zip

As soon as downloaded, extract the archive with unzip.

sudo apt set up unzip

sudo unzip matomo-latest.zip -d /var/www/

The -d choice specifies the goal listing. Matomo net information can be extracted to /var/www/matomo/.  Then we have to change the proprietor of this listing to www-data in order that the online server (Nginx) can write to this listing.

sudo chown www-data:www-data /var/www/matomo/ -R

Step 2: Create a Database and Consumer in MariaDB

Log into MariaDB database server with the next command. Since MariaDB is now utilizing unix_socket plugin to authentication consumer login, there’s no have to enter MariaDB root password. We simply have to prefix the mysql command with sudo.

sudo mysql

Alternatively, you can too use this command to login.

sudo mariadb

Then create a database for Matomo. This tutorial identify the database matomo. You need to use no matter identify you want.

create database matomo;

Create the database consumer. Once more, you need to use your most popular identify for this consumer. Exchange your-password with your most popular password.

create consumer [email protected] recognized by ‘your-password’;

Grant this consumer all privileges on the matomo database.

grant all privileges on matomo.* to [email protected] recognized by ‘your-password’;

Flush privileges and exit.

flush privileges;

exit;

Step three: Create Apache or Nginx Configuration File

Apache

When you favor to make use of Apache net server, then create a digital host configuration file in /and so forth/apache2/sites-available/ listing.

sudo nano /and so on/apache2/sites-available/matomo.conf

Put the next textual content into the file. Exchange the red-colored textual content with your precise knowledge. Don’t overlook to set A report for the area identify.

<VirtualHost *:80>
ServerAdmin [email protected] ServerName analytics.instance.com
DocumentRoot /var/www/matomo/

<Listing /var/www/matomo>
DirectoryIndex index.php
Choices FollowSymLinks
AllowOverride All
Require all granted
</Listing>

<Information “console”>
Choices None
Require all denied
</Information>

<Listing /var/www/matomo/misc/consumer>
Choices None
Require all granted
</Listing>

<Listing /var/www/matomo/misc>
Choices None
Require all denied
</Listing>

<Listing /var/www/matomo/vendor>
Choices None
Require all denied
</Listing>

ErrorLog $APACHE_LOG_DIR/matomo_error.log
CustomLog $APACHE_LOG_DIR/matomo_access.log mixed

</VirtualHost>

Save and shut the file. Then allow this digital host.

sudo a2ensite matomo.conf

Reload Apache net server for the change to take impact.

sudo systemctl reload apache2

Nginx

For those who choose to make use of Nginx net server, then create a matomo.conf file in /and so forth/nginx/conf.d/ listing.

sudo nano /and so on/nginx/conf.d/matomo.conf

Put the next textual content into the file. Exchange the red-colored textual content with your precise knowledge. Don’t overlook to set A report for the area identify.

server
pay attention [::]:80; # take away this if you don’t need Matomo to be reachable from IPv6
pay attention 80;
server_name analytics.instance.com;

access_log /var/log/nginx/matomo.entry.log;
error_log /var/log/nginx/matomo.error.log;

root /var/www/matomo/;

index index.php;

## solely permit accessing the next php information
location ~ ^/(index|matomo|piwik|js/index).php
embrace snippets/fastcgi-php.conf;
fastcgi_param HTTP_PROXY “”; # prohibit httpoxy: https://httpoxy.org/
fastcgi_pass unix:/run/php/php7.2-fpm.sock;

## wanted for HeatmapSessionRecording plugin
location = /plugins/HeatmapSessionRecording/configs.php
embrace snippets/fastcgi-php.conf;
fastcgi_param HTTP_PROXY “”;
fastcgi_pass unix:/run/php/php7.2-fpm.sock;

## deny entry to all different .php information
location ~* ^.+.php$
deny all;
return 403;

## serve all different information usually
location /
try_files $uri $uri/ =404;

## disable all entry to the next directories
location ~ /(config|tmp|core|lang)
deny all;
return 403; # exchange with 404 to not present these directories exist

location ~ /.ht
deny all;
return 403;

location ~ .(gif|ico|jpg|png|svg|js|css|htm|html|mp3|mp4|wav|ogg|avi|ttf|eot|woff|woff2|json)$
permit all;
## Cache photographs,CSS,JS and webfonts for an hour
## Growing the period might enhance the load-time, however might trigger previous information to point out after an Matomo improve
expires 1h;
add_header Pragma public;
add_header Cache-Management “public”;

location ~ /(libs|vendor|plugins|misc/consumer)
deny all;
return 403;

## correctly show textfiles in root listing
location ~/(.*.md|LEGALNOTICE|LICENSE)
default_type textual content/plain;

Save and shut the file. Check Nginx configuration, then reload Nginx for the modifications to take impact.

sudo nginx -t

sudo systemctl reload nginx

Step four: Install and Allow PHP Modules

Run the next instructions to put in PHP modules required or really helpful by Matomo.

sudo apt set up php-imagick php7.2-common php7.2-gd php7.2-json php7.2-curl  php7.2-zip php7.2-xml php7.2-mbstring php7.2-bz2 php7.2-intl

In case you are utilizing Apache net server, that you must reload it to make it run with these PHP modules.

sudo systemctl reload apache2

Nginx customers don’t have to reload.

Now it is best to be capable of go to the Matomo web-based set up wizard at http://analytics.example.com, however earlier than getting into any info, let’s allow HTTPS.

Step 5: Allow HTTPS

To encrypt the HTTP visitors once you go to the Matomo net interface, we will allow HTTPS by putting in a free TLS certificates issued from Let’s Encrypt. Run the next instructions to put in Let’s Encrypt shopper (certbot) on Ubuntu 18.04.

sudo apt set up software-properties-common
sudo add-apt-repository ppa:certbot/certbot
sudo apt replace
sudo apt set up certbot

Should you use Nginx, you additionally want to put in the Certbot Nginx plugin.

sudo apt set up python3-certbot-nginx

Then run the next command to acquire and set up TLS certificates.

sudo certbot –nginx –agree-tos –redirect –hsts –staple-ocsp –email [email protected] -d analytics.instance.com

When you use Apache, you additionally want to put in the Certbot Apache plugin.

sudo apt set up python3-certbot-apache

Then run this command to acquire and set up TLS certificates.

sudo certbot –apache –agree-tos –redirect –hsts –staple-ocsp –email [email protected] -d analytics.instance.com

Rationalization:

  • –nginx: Use the nginx plugin.
  • –apache: Use the Apache plugin.
  • –agree-tos: Comply with phrases of service.
  • –redirect: Drive HTTPS by 301 redirect.
  • –hsts: Add the Strict-Transport-Safety header to each HTTP response. Forcing browser to all the time use TLS for the area. Defends towards SSL/TLS Stripping.
  • –staple-ocsp: Allows OCSP Stapling. A legitimate OCSP response is stapled to the certificates that the server gives throughout TLS.

The certificates ought to now be obtained and routinely put in.

matomo install ubuntu

Step 6: End the Set up in your Web Browser

Go to https://analytics.example.com to launch the web-based set up wizard. Then click on Subsequent button.



Whoops, looks like something went wrong.

(1/1)
ErrorException

file_put_contents(): Only 0 of 363 bytes written, possibly out of free disk space

in Filesystem.php line 122
at HandleExceptions->handleError(2, ‘file_put_contents(): Only 0 of 363 bytes written, possibly out of free disk space’, ‘/var/www/html/uppi/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php’, 122, array(‘path’ => ‘/var/www/html/uppi/storage/framework/sessions/GGhSAG5A8lQJ84vKn9OvaRLt7Y467wGQoeJjxMMm’, ‘contents’ => ‘a:3:{s:6:"_token";s:40:"useXjkDCvjmPXstbM8IRjFaQDyCytfkNgzraknya";s:9:"_previous";a:1:{s:3:"url";s:204:"http://usaserver4.com/uppi?domain=blogpong&image_url=https%3A%2F%2Fblogpong.com%2Fwp-content%2Fuploads%2F2019%2F01%2F1547736600_816_install-matomo-web-analytics-piwik-on-ubuntu-18-04-with-apache-nginx.png";}s:6:"_flash";a:2:{s:3:"old";a:0:{}s:3:"new";a:0:{}}}’, ‘lock’ => true))
at file_put_contents(‘/var/www/html/uppi/storage/framework/sessions/GGhSAG5A8lQJ84vKn9OvaRLt7Y467wGQoeJjxMMm’, ‘a:3:{s:6:"_token";s:40:"useXjkDCvjmPXstbM8IRjFaQDyCytfkNgzraknya";s:9:"_previous";a:1:{s:3:"url";s:204:"http://usaserver4.com/uppi?domain=blogpong&image_url=https%3A%2F%2Fblogpong.com%2Fwp-content%2Fuploads%2F2019%2F01%2F1547736600_816_install-matomo-web-analytics-piwik-on-ubuntu-18-04-with-apache-nginx.png";}s:6:"_flash";a:2:{s:3:"old";a:0:{}s:3:"new";a:0:{}}}’, 2)in Filesystem.php line 122
at Filesystem->put(‘/var/www/html/uppi/storage/framework/sessions/GGhSAG5A8lQJ84vKn9OvaRLt7Y467wGQoeJjxMMm’, ‘a:3:{s:6:"_token";s:40:"useXjkDCvjmPXstbM8IRjFaQDyCytfkNgzraknya";s:9:"_previous";a:1:{s:3:"url";s:204:"http://usaserver4.com/uppi?domain=blogpong&image_url=https%3A%2F%2Fblogpong.com%2Fwp-content%2Fuploads%2F2019%2F01%2F1547736600_816_install-matomo-web-analytics-piwik-on-ubuntu-18-04-with-apache-nginx.png";}s:6:"_flash";a:2:{s:3:"old";a:0:{}s:3:"new";a:0:{}}}’, true)in FileSessionHandler.php line 83
at FileSessionHandler->write(‘GGhSAG5A8lQJ84vKn9OvaRLt7Y467wGQoeJjxMMm’, ‘a:3:{s:6:"_token";s:40:"useXjkDCvjmPXstbM8IRjFaQDyCytfkNgzraknya";s:9:"_previous";a:1:{s:3:"url";s:204:"http://usaserver4.com/uppi?domain=blogpong&image_url=https%3A%2F%2Fblogpong.com%2Fwp-content%2Fuploads%2F2019%2F01%2F1547736600_816_install-matomo-web-analytics-piwik-on-ubuntu-18-04-with-apache-nginx.png";}s:6:"_flash";a:2:{s:3:"old";a:0:{}s:3:"new";a:0:{}}}’)in Store.php line 128
at Store->save()in StartSession.php line 88
at StartSession->terminate(object(Request), object(Response))in Kernel.php line 218
at Kernel->terminateMiddleware(object(Request), object(Response))in Kernel.php line 189
at Kernel->terminate(object(Request), object(Response))in index.php line 58


” alt=”matomo install ubuntu 18.04″ width=”904″ />

It’ll verify in case your system meets the necessities like PHP extensions. If all necessities are met, then click on Subsequent.

matomo ubuntu php extensions

Within the subsequent step, enter the MariaDB username, password and database identify your created earlier. You need to use the default worth in different fields.

matomo mariadb database

After clicking Subsequent, the set up wizard will routinely create some tables within the database. Click on Subsequent to proceed.

matomo ubuntu apache

Within the subsequent display, create an admin consumer for the Matomo net interface.

matomo ubuntu nginx

After creating the admin consumer, you’ll want to add an internet site to gather analytics knowledge.

matomo analytics ubuntu 18.04

Then it’s essential to add the JavaScript monitoring code to your web site.

matomo installation

As soon as that’s accomplished. Click on Subsequent button and your Matomo set up is full. Now you possibly can log into the Matomo dashboard and think about customer knowledge.

matomo dashboard

Set Up Cron Jobs for Medium and Excessive-Visitors Web sites

In case your web site has hundreds of web page views per day, it’s essential to arrange a cron job to auto-archive Matomo reviews. Create the Cron job file with the next command.

sudo nano /and so on/cron.d/matomo-archive

Then add the next strains to the file.

MAILTO=”[email protected]”
5 * * * * www-data /usr/bin/php /var/www/matomo/console core:archive –url=https://analytics.example.com > /var/log/matomo-archive.log

Save and shut the file. This Cron job will run each hour at 5 minutes previous.

Easy methods to Set Up E mail Notification

If there are multiple consumer, then it’s a good suggestion to make Matomo have the ability to ship e mail notification like password reset emails. For the best way to arrange an e mail server, please take a look at the next tutorial:

In the event you don’t need to run your personal e mail server, you possibly can arrange SMTP relay as an alternative. Please see the next tutorial.

Different Issues To Do

That’s it! I hope this tutorial helped you put in Matomo on Ubuntu 18.04 server with Apache or Nginx. As all the time, when you discovered this publish helpful, then subscribe to our free publication to get extra ideas and tips. Take care ?

Price this tutorial

[Total: 0 Average: 0]

(perform(d, s, id)
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = “//connect.facebook.net/zh_CN/sdk.js#xfbml=1&version=v2.8&appId=961591023917170”;
fjs.parentNode.insertBefore(js, fjs);
(doc, ‘script’, ‘facebook-jssdk’));