In this tutorial, we will explain the installation of Piwik on a Debian 9 VPS. Piwik is a free and open-source web analytics tool written by a team of international developers. It can run on a webserver with PHP and MySQL/MariaDB. It tracks online visits to one or more websites and displays reports on these visits for analysis. Among many things, it provides real time data updates, content tracking, goal conversion tracking, event tracking, analytics for e-commerce websites, site search analytics, geolocation and much more.
You have to install the following requirements to run Piwik on your Debian 9 VPS:
- Web server such as Apache, Nginx, etc.
- PHP version 5.5.9 or newer, with pdo and pdo_mysql, or the mysqli extension enabled
- MySQL/MariaDB version 5.5 or newer.
Get started
Log in to your VPS via SSH as user root
ssh root@IP_ADDRESS -p PORT_NUMBER
replace ‘IP_ADDRESS’ and ‘PORT_NUMBER’ with your actual IP address and SSH port number
and execute the following command to make sure that all the system packages are up to date
apt-get update && apt-get update
Install Apache
To install Apache web server, run the following command
apt-get install apache2
Once it is installed enable the service to start on boot
systemctl enable apache2
Verify that Apache is running on your server
systemctl status apache2 ● apache2.service - The Apache HTTP Server Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled) Active: active (running)
Install PHP
Piwik is a PHP based application, so we will install PHP 7 on the server
apt-get install php php-mysql php-mbstring php-xml
Install MariaDB and create database
Now, we have our Apache web server and PHP setup and ready and the next step is to install a database server. We will install the latest version of MariaDB server
apt-get install mariadb-server
After it is installed, start the database server and make it to automatically start on boot
apt-get start mariadb apt-get enable mariadb
Run the mysql_secure_installation
script provided by MariaDB, to set your root password and enhance the security of your MariaDB server. Next, login to the MariaDB server as user root
mysql -u root -p
and create a database and user for Piwik
mysql> CREATE DATABASE piwik; mysql> GRANT ALL PRIVILEGES on piwik.* to 'piwikuser'@'localhost' identified by 'PASSWORD'; mysql> FLUSH PRIVILEGES; mysql> exit
Don’t forget to replace ‘PASSWORD’ with an actual, strong password.
Install Piwik
We have installed full LAMP stack and your Debian 9 VPS meets all the requirements to run Piwik. The final step is to install and configure Piwik.
Download the latest version of the application from their official website
wget https://builds.piwik.org/piwik.zip
and unpack the archive to the document root directory on your server
unzip piwik.zip -d /var/www/html/
This will create a new directory ‘piwik’ containing the necessary files and directories.
Change the ownership of the piwik directory
chown -R www-data:www-data /var/www/html/piwik
Finally, go to http://yourdomain.tld/piwik
or http://yourip/piwik
and follow the on-screen instructions to complete the Piwik installation.
For more details on how to configure Piwik, please read their official documentation.
PS. If you liked this post please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.