如何在 Debian 9 上安装 Matomo Web Analytics如何在 Debian 9 上安装 Matomo Web Analytics如何在 Debian 9 上安装 Matomo Web Analytics如何在 Debian 9 上安装 Matomo Web Analytics
  • 文章
  • 正则表达式
    • 工具
  • 登录
找到的结果: {phrase} (显示: {results_count} 共: {results_count_total})
显示: {results_count} 共: {results_count_total}

加载更多搜索结果...

搜索范围
模糊匹配
搜索标题
搜索内容
发表 admin at 2025年2月28日
类别
  • 未分类
标签

如何在 Debian 9 上安装 Matomo Web Analytics

本教程适用于这些操作系统版本

  • Debian 11(Bullseye)
  • Debian 9(Stretch)

在此页

  1. 要求
  2. 先决条件
  3. 初始步骤
  4. 第 1 步 - 安装 MySQL 并为 Matomo 创建数据库
  5. 第 2 步 - 安装 PHP 和必要的 PHP 扩展
  6. 第 3 步 - 安装 acme.sh 客户端并获取 Let\>)
  7. 第 3 步 - 安装 NGINX 并为 Matomo 配置 NGINX
  8. 第 4 步 - 安装 Matomo Analytics
  9. 第 5 步 - 完成 Matomo 分析设置
  10. 链接

Matomo(以前称为 Piwik)是一个免费的开源网络分析应用程序,由国际开发人员团队开发,在 PHP/MySQL 网络服务器上运行。它跟踪对一个或多个网站的在线访问,并显示这些访问的报告以供分析。您可以将其视为 Google Analytics 的替代品。 Matomo 是开源的,其代码可在 Github 上公开获取。它具有的一些功能包括:A/B 测试、热图、漏斗、跟踪和报告 API、Google AdWords、Facebook Ads、Bing Ads、每次点击成本 (CPC) 等。本教程将向您展示如何在使用 Nginx 作为 Web 服务器的 Debian 9 (stretch) 系统,我们将使用 Lets Encrypt SSL 证书保护网站。

要求

要在您的 Debian 系统上运行 Matomo (Piwik),您需要一些东西:

  • 网络服务器,例如 Apache 或 Nginx。
  • PHP 版本 5.5.9 或更高版本,带有 pdo 和 pdo_mysql 或 mysqli、gd、xml、curl 和 mbsting 扩展。推荐 PHP 7+。
  • MySQL 5.5 或更高版本,或等效的 MariaDB 版本。推荐 MySQL 5.7+。

先决条件

  • 运行 Debian 9 (stretch) 的操作系统。
  • 具有 sudo 权限的非根用户。

初始步骤

检查您的 Debian 版本:

lsb_release -ds
# Debian GNU/Linux 9.6 (stretch)

设置时区:

dpkg-reconfigure tzdata

更新您的操作系统包(软件)。这是重要的第一步,因为它确保您拥有操作系统默认软件包的最新更新和安全修复程序:

apt update && apt upgrade -y

安装 Debian 操作系统基本管理所需的一些基本软件包:

apt install -y curl wget vim git unzip socat sudo

第 1 步 - 安装 MySQL 并为 Matomo 创建数据库

Matomo 支持 MySQL 和 MariaDB 数据库。 Debian 团队用 MariaDB 取代了 MySQL 作为 Debian 9(stretch)的默认数据库,因此在本教程中,我们将使用 MariaDB 作为数据库服务器。如果你想安装原始的 MySQL,你可以添加和使用由 Oracle 维护的官方 MySQL 存储库。

安装 MariaDB 数据库服务器:

sudo apt install -y mariadb-server

检查 MariaDB 版本:

mysql --version
# mysql  Ver 14.14 Distrib 5.7.24, for Linux (x86_64) using  EditLine wrapper

运行 mysql_secure installation 脚本以提高 MariaDB 安全性并为 MariaDB root 用户设置密码:

sudo mysql_secure_installation

回答每个问题:

Enter current password for root (enter for none): Press Enter
Set root password? [Y/n] y
New password: your_secure_password
Re-enter new password: your_secure_password
Remove anonymous users? [Y/n] Y
Disallow root login remotely? [Y/n] Y
Remove test database and access to it? [Y/n] Y
Reload privilege tables now? [Y/n] Y

以根用户身份连接到 MariaDB shell:

sudo mysql -u root -p
# Enter password

为 Matomo 创建一个空的 MariaDB 数据库和用户并记住凭据:

mysql> CREATE DATABASE dbname;
mysql> GRANT ALL ON dbname.* TO 'username' IDENTIFIED BY 'password';
mysql> FLUSH PRIVILEGES;

退出 MariaDB:

mysql> exit

将 dbname、username 和 password 替换为您自己的名称。

第 2 步 - 安装 PHP 和必要的 PHP 扩展

安装 PHP,以及必要的 PHP 扩展:

sudo apt install -y php7.0 php7.0-cli php7.0-fpm php7.0-common php7.0-curl php7.0-gd php7.0-xml php7.0-mbstring php7.0-mysql

检查 PHP 版本:

php --version

# PHP 7.0.33-0+deb9u1 (cli) (built: Dec  7 2018 11:36:49) ( NTS )
# Copyright (c) 1997-2017 The PHP Group
# Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
# with Zend OPcache v7.0.33-0+deb9u1, Copyright (c) 1999-2017, by Zend Technologies

PHP-FPM 服务在 Debian 9 系统重启时自动启动和启用,因此无需手动启动和启用。我们可以继续下一步,即从 Lets Encrypt CA 获取免费的 SSL 证书。

第 3 步 - 安装 acme.sh 客户端并获取 Lets Encrypt 证书(可选)

没有必要使用 HTTPS 保护您的网站,但这是保护您的网站流量的好习惯。为了从 Lets Encrypt 获得 TLS 证书,我们将使用 acme.sh 客户端。 Acme.sh 是一个纯 Unix shell 软件,用于以零依赖从 Lets Encrypt 获取 TLS 证书。

下载并安装 acme.sh:

sudo mkdir /etc/letsencrypt
git clone https://github.com/Neilpang/acme.sh.git
cd acme.sh 
sudo ./acme.sh --install --home /etc/letsencrypt --accountemail 
cd ~

检查 acme.sh 版本:

/etc/letsencrypt/acme.sh --version
# v2.8.0

为您的域/主机名获取 RSA 和 ECC/ECDSA 证书:<br>

# RSA 2048
sudo /etc/letsencrypt/acme.sh --issue --standalone --home /etc/letsencrypt -d example.com --keylength 2048
# ECDSA
sudo /etc/letsencrypt/acme.sh --issue --standalone --home /etc/letsencrypt -d example.com --keylength ec-256

运行上述命令后,您的证书和密钥将位于:

  • 对于 RSA:/etc/letsencrypt/example.com 目录。
  • 对于 ECC/ECDSA:/etc/letsencrypt/example.com_ecc 目录。

第 3 步 - 安装 NGINX 并为 Matomo 配置 NGINX

Matomo 可以很好地与许多流行的网络服务器软件一起工作。在本教程中,我们选择了 Nginx。

从 Debian 存储库下载并安装 Nginx:

sudo apt install -y nginx

检查 Nginx 版本:

sudo nginx -v
# nginx version: nginx/1.10.3

通过运行以下命令为 Matomo 配置 Nginx:

sudo vim /etc/nginx/sites-available/matomo.conf

并使用以下配置填充文件:

server {

listen [::]:443 ssl http2;
listen 443 ssl http2;
listen [::]:80;
listen 80;

server_name example.com;
root /var/www/matomo/;
index index.php;

ssl_certificate /etc/letsencrypt/example.com/fullchain.cer;
ssl_certificate_key /etc/letsencrypt/example.com/example.com.key;
ssl_certificate /etc/letsencrypt/example.com_ecc/fullchain.cer;
ssl_certificate_key /etc/letsencrypt/example.com_ecc/example.com.key;

location ~ ^/(index|matomo|piwik|js/index).php {
include snippets/fastcgi-php.conf;
fastcgi_param HTTP_PROXY "";
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
}

location = /plugins/HeatmapSessionRecording/configs.php {
include snippets/fastcgi-php.conf;
fastcgi_param HTTP_PROXY "";
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
}

location ~* ^.+\.php$ {
deny all;
return 403;
}

location / {
try_files $uri $uri/ =404;
}

location ~ /(config|tmp|core|lang) {
deny all;
return 403;
}

location ~ \.(gif|ico|jpg|png|svg|js|css|htm|html|mp3|mp4|wav|ogg|avi|ttf|eot|woff|woff2|json)$ {
allow all;
}

location ~ /(libs|vendor|plugins|misc/user) {
deny all;
return 403;
}

}

注意:有关 Matomo 的完整和生产就绪的 Nginx 配置,请访问 https://github.com/matomo-org/matomo-nginx。

通过将文件链接到 sites-enabled 目录来激活新的 matomo.conf 配置。

sudo ln -s /etc/nginx/sites-available/matomo.conf /etc/nginx/sites-enabled

检查 Nginx 配置是否有语法错误:

sudo nginx -t

重新加载 Nginx 服务:

sudo systemctl reload nginx.service

第 4 步 - 安装 Matomo Analytics

创建 /var/www 目录:

sudo mkdir -p /var/www

导航到 /var/www 目录:

cd /var/www/

通过 wget 下载最新版本的 Matomo 并解压:

sudo wget https://builds.matomo.org/matomo.zip && sudo unzip matomo.zip

删除下载的 matomo.zip 文件:

sudo rm matomo.zip

将 /var/www/matomo 目录的所有权更改为 www-data user:

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

第 5 步 - 完成 Matomo Analytics 设置

在网络浏览器中打开您的站点,然后按照 Matomo 网络安装向导进行操作。

首先,应该会出现 Matomo 欢迎信息。单击“下一步”按钮:

之后,您将看到一个“系统检查”页面。如果缺少某些内容,您将看到一条警告。如果所有内容都标有绿色复选标记,请单击“下一步”按钮继续下一步:

接下来,填写数据库详细信息并单击“下一步”按钮:

如果数据库设置一切顺利,您应该会看到“成功创建表!”消息:

创建 Matomo 超级用户帐户并单击“下一步”按钮:

接下来,设置您想要使用 Matomo 跟踪和分析的第一个网站。稍后,您可以添加更多站点以使用 Matomo 进行跟踪:

接下来,您将获得网站的 JavaScript 跟踪代码,您需要添加该代码才能开始跟踪。

接下来,您应该会看到 Matomo 安装完成。

恭喜!您的 Matomo 安装已完成。

链接

  • https://matomo.org/ <李>
  • https://github.com/matomo-org/matomo-nginx

©2015-2025 艾丽卡 support@alaica.com