how to install Matomo (Piwik) on Debian

10th Mar 2018 Karibu

With more than 3 millions downloads, and large companies like T-Mobile, Wikimedia, Forbes,.. using it, Matomo (previously Piwik) is the most popular opensource web analytics app.

Great alternative to Google Analytics, Piwik as been here for 10 years. The team behind the project, decided recently (Jan 2018) to change their name as you can read in their announcement to become Matomo (It means honesty in Japanese by the way).

Here are some of the key features of Matomo:

  • Real time update
  • Customizable Dashboard
  • Advanced analytics for Ecommerce
  • Goal conversion tracking
  • Site Search Analytics
  • Geolocation
  • Site speed & pages speed reports
  • Track traffic from search engines
  • Custom Alerts
  • And a IOS, Android application!

You can have the full list of features in their dedicated page.

Interested to give it shot? Try their demo.

Now let's see how to install Matomo (formerly Piwik) on your Linux server (Debian in my case.)

Installation Steps

First you will need to have a working LAMP server. If it is not the case, you can check my recent article on how to install LAMP. Luckily, they maintained a debian/ubuntu repo, which makes it very easy to install.

1) Add their repo to your sources list

Simply run:

wget https://debian.piwik.org/repository.gpg -qO piwik-repository.gpg
cat piwik-repository.gpg | sudo apt-key add -

Then add their repo to your sources.list file

nano /etc/apt/sources.list

and add

deb https://debian.piwik.org/ piwik main

Refresh your package list

sudo apt-get update


2) Install Piwik from the repo and the required PHP dependencies

You will need to install some dependencies first.

sudo apt update
sudo apt install piwik php-curl php-fpm php-gd php-zip php-mbstring php-xml


3) Correct permissions and remove the readme

rm "/usr/share/doc/piwik/README.md.gz"
chmod +w /usr/share/piwik/piwik.js
chown www-data:www-data /usr/share/piwik/piwik.js


4) Create a dedicated MySQL database

Now you will need to create a dedicated MySQL database and a dedicated user. The easiest way to do it will be through phpmyadmin. Once done, you can go to the next step.

5) Update the virtualhost configuration

Before accessing Piwik and finalizing the installation, it will be better to create a virtualhost with a subdomain to access directly your Piwik instance. Piwik comes with a configuation ready, accessible through /piwik, but I prefer configuring entirely mine.

Delete previous configuration

sudo rm /etc/apache2/conf-available/piwik.conf 
sudo rm /etc/apache2/conf-enabled/piwik.conf 

And create a new virtual host

sudo nano /etc/apache2/sites-available/piwik.conf

And add

<VirtualHost *:80>

        ServerAdmin webmaster@localhost
        ServerName piwik.domain.tld
        DocumentRoot /usr/share/piwik

        <Directory /usr/share/piwik>
           DirectoryIndex index.php
           Options FollowSymLinks
           AllowOverride All
           Require all granted
        </Directory>

        <Files "console">
           Options None
           Require all denied
        </Files>

        <Directory /usr/share/piwik/misc/user>
           Options None
           Require all granted
        </Directory>

        <Directory /usr/share/piwik/misc>
           Options None
           Require all denied
        </Directory>

        <Directory /usr/share/piwik/vendor>
           Options None
           Require all denied
        </Directory>

        ErrorLog ${APACHE_LOG_DIR}/matomo_error.log
        CustomLog ${APACHE_LOG_DIR}/matomo_access.log combined

</VirtualHost>

Enable the configuration

sudo a2ensite piwik

and reload your configuration

systemctl reload apache2


6) Run the web based installation panel

Now, simply go to the configured URL to launch the installation panel. It will check that you have all required dependencies, if it is not the case, you will need to fix them. Once you would have created a user/password, and entered your database details, it will generate a tracking code to add to your website. You can either do it manually or use one of the available plugin if you use some CMS, to facilitate this.

PS: If you cannot access to piwik, try adding index.php at the end (I had to clear my cache to be able to access it with the new URL)

That's it, you should now have access to great analytics for your website.

Next could be to add SSL certificate to your piwik instance.

Thank Matomo!

Gravatar

Loves to discover web-based apps to install on his own server@home and write articles about it

0 Comments:

Add a comment