How to Install Matomo Web Analytics With Apache On FreeBSD

Web analytics is a system for collecting and analyzing data. This system really helps you understand user behavior on the site and track their interactions with the articles or products you market. Based on the results of data analysis, it becomes clear how to improve the product or some stages of interaction with the client.
For example, an online store launched contextual advertising on social networks, spent a large budget, and sales still did not increase. With the help of web analytics, we found that customers simply put the product in their cart and left the site. This may mean that you need to work on the order form: make it shorter and clearer so that clients can fill in all the fields in a few minutes.

Web analytics is necessary for specialists who analyze data, create products, promote them on the network and manage the processes that have been generated by Web analytics

Working with web analytics looks different in every profession.


Matomo, previously known as Piwik, is a free and open source web analytics software that can track website visits and display reports for data and analysis of the number of visitors. Matomo is written in PHP and is licensed under the GPL. MAtomo can work with MySQL or MariaDB database servers. Matomo's capabilities are fantastic, it can provide reports to track users on your website. This includes referring search engines and keywords, language, page visits, file visitors, downloads, and more. With Matomo's capabilities it is becoming increasingly popular, if you could say it is almost equivalent to Google Analytics in tracking website visitors.


1. System Requirements

OS: FreeBSD 13.2
IP address: 192.168.5.2
Hostname: ns3
Web server: apache24
Matomo version: php82-matomo-4.13.3
PHP version: PHP82
PHP-FPM
Dependencies: php82-ctype php82-curl php82-dom php82-fileinfo php82-filter php82-gd php82-iconv php82-intl php82-mbstring php82-mysqli php82-opcache php82-pdo php82-pdo_mysql php82-posix php82-readline php82-session php82-simplexml php82-soap php82-sockets php82-sqlite3 php82-tidy php82-tokenizer php82-xml php82-zlib php82-pdo_mysql php82-pecl-mcrypt php82-pecl-memcache php82-pecl-memcached


2. Create Database MySQL Server

Matomo can only be run using MySQL or MariaDB as the backend database. At the time of writing this article, Matomo requires at least MySQL Server v8 or MariaDB v10. x. In this article we will install and use MySQL server as a database for Matomo Web Analytics. Let's assume that MySQL Server has been installed on your FreeBSD server, so we just create a Matomo database.

Login to the MySQL Server database.
root@ns3:~ # mysql -u root -p
Enter password: router123
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 8.0.35 Source distribution

Copyright (c) 2000, 2023, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

root@localhost [(none)]>
After you have successfully logged in to the MySQL server database, create database matomo.
root@localhost [(none)]> CREATE DATABASE matomo;
Query OK, 1 row affected (0.04 sec)

root@localhost [(none)]> CREATE USER 'usermatomo'@'localhost' IDENTIFIED BY 'router123';
Query OK, 0 rows affected (0.04 sec)

root@localhost [(none)]> GRANT ALL PRIVILEGES ON matomo.* TO 'usermatomo'@'localhost';
Query OK, 0 rows affected (0.03 sec)

root@localhost [(none)]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.02 sec)

root@localhost [(none)]>


3. Install Matomo

Matomo Analysis is a PHP-based application or written in PHP, so it requires PHP dependencies. If you don't install the PHP dependencies for Matomo, don't expect MAtomo to run on FreeBSD servers. There are lots of dependencies that must be installed, all of these dependencies complement each other.

Apart from that, Matomo also works with MySQL or MariaDB databases. So it is very important for us to prepare the dependencies that connect Matomo with the database. PHP dependencies for communication with the database server are php82-mysqli, php82-pdo, php82-pdo_mysql and php82-pdo_mysql.
root@ns3:~ # pkg install php82-ctype php82-curl php82-dom php82-fileinfo php82-filter php82-gd php82-iconv php82-intl php82-mbstring php82-mysqli php82-opcache php82-pdo php82-pdo_mysql php82-posix php82-readline php82-session php82-simplexml php82-soap php82-sockets php82-sqlite3 php82-tidy php82-tokenizer php82-xml php82-zlib php82-pdo_mysql
root@ns3:~ # pkg install php82-pecl-mcrypt php82-pecl-memcache php82-pecl-memcached
Once all the above dependencies are installed on the FreeBSD server, run the following command to install Matomo.
root@ns3:~ # cd /usr/ports/www/matomo
root@ns3:/usr/ports/www/matomo # make config
root@ns3:/usr/ports/www/matomo # make install clean


4. Matomo Configuration

Actually Matomo does not have a configuration file, because Matomo runs on the Apache web server, what you have to configure is Apache. Open the /usr/local/etc/apache24/httpd.conf file, at the end of the script file, add the script below.

Alias /matomo /usr/local/www/matomo
   AcceptPathInfo On
   <Directory /usr/local/www/matomo>
     DirectoryIndex index.php
     Options FollowSymLinks
     AllowOverride All
     <IfVersion < 2.4>
        Order allow,deny
        Allow from all
     </IfVersion>
     <IfVersion >= 2.4>
       Require all granted
     </IfVersion>
   </Directory>

Don't forget, you have to activate PHP-FPM. In this article we assume PHP-FPM has been installed on the FreeBSD server, so we will not review PHP-FPM.

All files resulting from the Matomo installation are stored in the /usr/local/www/matomo directory. Give ownership and permissions to the directory.
root@ns3:~ # chown -R www:www /usr/local/www/matomo
root@ns3:~ # chmod -R 775 /usr/local/www/matomo
To prepare to run Matomo, you restart apache.
root@ns3:~ # service apache24 restart
Matomo Web Analytics is run with a web browser, you open the Google Chrome browser, and type "http://192.168.5.2/matomo/", if you haven't missed anything in the configuration above, it should appear like the image below.



Click Next to start the installation.

Matomo starts installing and checking the server environment for the installation process. Make sure all requirements and settings are marked in green, as in the image below.


Type in the MySQL Server database details for your Matomo web analytics. Make sure you have entered the correct database username and password. Then click Next again.


After you have successfully filled in everything, you will be directed to the main Matomo dashboard, as shown in the image below.


Congratulations, you have successfully and finished installing Matomo Web Analytics. on FreeBSD servers. With Matomo installed on a private FreeBSD server, you add another site and start tracking it using Matomo Web Analytics.
Iwan Setiawan

I Like Adventure: Mahameru Mount, Rinjani Mount I Like Writer FreeBSD

Post a Comment

Previous Post Next Post