Project

General

Profile

Support #957

Install Matomo on FreeBSD 12

Added by Daniel Curtis 23 days ago.

Status:
New
Priority:
Normal
Assignee:
Category:
Installation
Target version:
Start date:
02/12/2021
Due date:
% Done:

0%

Estimated time:

Description

This is a guide on setting up Matomo with nginx on FreeBSD 12.

Prepare the Environment

  • Before installation of the components, make sure everything is up to date using the following command:
    pkg update && pkg upgrade
    
  • Create the matomo user:
    pw user add -n matomo -m -s /sbin/nologin -c "Matomo" 
    

Install MySQL Server

  • Install mariadb105-server and mariadb105-client:
    pkg install mariadb105-{server,client}
    
  • Enable and start mariadb at boot:
    sysrc mysql_enable=YES
    service mysql-server start
    
  • Prepare the database for use by running the secure installation:
    mysql_secure_installation
    
    • NOTE: Choose a strong root password and answer yes to all questions.

Create MySQL Databases and Users

  • Login to MySQL and create appropriate databases and users.
    mysql -u root -p
    
    • and run the following SQL queries to create the matomodb database and matomouser user:
      CREATE DATABASE matomodb;
      
      CREATE USER 'matomouser'@'localhost' IDENTIFIED BY 'SuperSecretPassword';
      
      GRANT GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, INDEX, DROP, ALTER, CREATE TEMPORARY TABLES, LOCK TABLES ON matomodb.* TO 'matomouser'@'localhost';
      
      GRANT FILE ON *.* TO 'matomouser'@'localhost';
      
      FLUSH PRIVILEGES;
      
      quit
      

Install Nginx

  • Install Nginx
    pkg install nginx
    
  • Start and enable nginx at boot:
    sysrc nginx_enable=YES
    service nginx start
    
  • Create a configuration directory to make managing individual server blocks easier
    mkdir /usr/local/etc/nginx/conf.d
    
  • Edit the main nginx config file:
    vi /usr/local/etc/nginx/nginx.conf
    
    • And strip down the config file and add the include statement at the end to make it easier to handle various server blocks:
      worker_processes  1;
      error_log  /var/log/nginx-error.log;
      
      events {
          worker_connections  1024;
      }
      
      http {
          include       mime.types;
          default_type  application/octet-stream;
          sendfile        on;
          keepalive_timeout  65;
      
          # Load config files from the /etc/nginx/conf.d directory
          include /usr/local/etc/nginx/conf.d/*.conf;
      }
      

Install Matomo

  • Install Matomo:
    pkg install php74-matomo
    
  • Create the matomo php-fpm pool config file:
    vi /usr/local/etc/php-fpm.d/matomo.conf
    
    • And add the following:
      [matomo]
      user = matomo
      group = www
      listen = /var/run/matomo.sock
      listen.owner = matomo
      listen.group = www
      pm = dynamic
      pm.max_children = 5
      pm.start_servers = 2
      pm.min_spare_servers = 1
      pm.max_spare_servers = 3
      php_admin_value[session.save_path] = "/usr/local/www/matomo/tmp" 
      php_admin_value[always_populate_raw_post_data] = "-1" 
      
  • Create a matomo server block:
    vi /usr/local/etc/nginx/conf.d/matomo.conf
    
    • Add the following:
      upstream matomo-php-handler {
        server unix:/var/run/matomo.sock;
      }
      
      server {
        listen 80;
        server_name matomo.example.com;
        root /usr/local/www/matomo/;
        index index.php;
      
        location = /robots.txt {
          allow all;
          log_not_found off;
          access_log off;
        }
      
        location ~ ^/(?:CHANGELOG\.md|config|README.md){
          deny all;
        }
      
        location / {
          try_files $uri $uri/ =404;
        }
      
        location ~ \.php(?:$|/) {
          fastcgi_split_path_info ^(.+\.php)(/.+)$;
          include fastcgi_params;
          fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
          fastcgi_param PATH_INFO $fastcgi_path_info;
          fastcgi_pass matomo-php-handler;
          fastcgi_intercept_errors on;
        }
      }
      
  • Change the ownership of the matomo directory:
    chown -R matomo:www /usr/local/www/matomo
    
  • Restart nginx and start php-fpm:
    sysrc php_fpm_enable=YES
    service php-fpm start
    service nginx restart
    

No data to display

Also available in: Atom PDF