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

加载更多搜索结果...

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

如何在 Debian 11 上安装 Matomo Web Analytics

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

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

在此页

  1. 先决条件
  2. 安装 Apache、MariaDB 和 PHP
  3. 为 Matomo 创建一个 MariaDB 数据库
  4. 下载 Matomo
  5. 为 Matomo 配置 Apache
  6. 访问 Matomo 网络用户界面
  7. 使用 Lets Encrypt SSL 保护 Matomo
  8. 结论

Matomo,以前称为 Piwik,是由开发人员社区开发的免费开源 Web 分析应用程序。它用于跟踪您的网站并提供有关您的网站及其访问者的详细信息,包括他们使用的搜索引擎和关键字、他们使用的语言、他们喜欢的页面、他们下载的文件等等。它提供了许多功能,包括 Google AdWords、Facebook Ads、Yahoo、搜索营销、跟踪和报告 API 以及每次点击成本 (CPC)。

在本教程中,我将向您展示如何使用 Apache2 Web 服务器和免费的 Lets Encrypt SSL 证书在 Debian 11 上安装 Matomo。

先决条件

  • 运行 Debian 11 的服务器。
  • 用您的服务器 IP 指向的有效域名。
  • 在服务器上配置了根密码。

安装 Apache、MariaDB 和 PHP

首先,您需要为您的服务器安装 Apache Web 服务器、MariaDB 数据库服务器、PHP 和其他 PHP 扩展。您可以通过运行以下命令来安装所有这些:

apt-get install apache2 mariadb-server php libapache2-mod-php php-cli php-fpm php-fpm php-json php-json php-common php-mysql php-zip php-gd php-mbstring php-curl php-xml php-pear php-bcmath curl unzip -y

安装所有包后,使用以下命令启动并启用 Apache 和 MariaDB 服务:

systemctl start apache2 mariadb
systemctl enable apache2 mariadb

完成后,您可以继续下一步。

为 Matomo 创建一个 MariaDB 数据库

Matomo 使用 MariaDB 作为数据库后端。所以你需要为 Matomo 创建一个数据库和用户。

首先,使用以下命令登录 MariaDB:

mysql

登录后,使用以下命令创建数据库和用户:

MariaDB [(none)]> CREATE DATABASE matomodb;
MariaDB [(none)]> CREATE USER 'matomo'@'localhost' IDENTIFIED BY 'password';

接下来,使用以下命令授予 Matomo 数据库的所有权限:

MariaDB [(none)]> GRANT ALL ON matomodb.* TO 'matomo'@'localhost' WITH GRANT OPTION;

接下来,使用以下命令刷新权限并退出 MariaDB shell:

MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> EXIT;

MariaDB数据库配置完成后,就可以进行下一步了。

下载 Matomo

接下来,访问 Matomo 官方网站并使用以下命令下载最新版本的 Matomo:

wget http://builds.matomo.org/matomo-latest.zip

下载完成后,使用以下命令解压缩下载的文件:

unzip matomo-latest.zip

接下来,将提取的目录移动到 Apache web 根目录:

mv matomo /var/www/html/matomo

接下来,更改 Matomo 目录的所有权和权限:

chown -R www-data:www-data /var/www/html/matomo
chmod -R 755 /var/www/html/matomo

完成后,您可以继续下一步。

为 Matomo 配置 Apache

接下来,您需要创建一个 Apache 虚拟主机配置文件来在互联网上托管 Matomo。您可以使用以下命令创建它:

nano /etc/apache2/sites-available/matomo.conf

添加以下行:

<VirtualHost *:80>

ServerAdmin 
ServerName matomo.example.com
DocumentRoot /var/www/html/matomo/

<Directory /var/www/html/matomo>
DirectoryIndex index.php
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>

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

<Directory /var/www/html/matomo/misc/user>
Options None
Require all granted
</Directory>

<Directory /var/www/html/matomo/misc>
Options None
Require all denied
</Directory>

<Directory /var/www/html/matomo/vendor>
Options None
Require all denied
</Directory>

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


</VirtualHost>

完成后保存并关闭文件,然后使用以下命令激活 Matomo 虚拟主机和 Apache 重写模块:

a2ensite matomo.conf
a2enmod rewrite

接下来,重新启动 Apache 服务以应用更改:

systemctl restart apache2

您还可以使用以下命令检查 Apache 状态:

systemctl status apache2

您将获得以下输出:

? apache2.service - The Apache HTTP Server
     Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
     Active: active (running) since Sun 2022-03-06 06:33:24 UTC; 5s ago
       Docs: https://httpd.apache.org/docs/2.4/
    Process: 55482 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCESS)
   Main PID: 55486 (apache2)
      Tasks: 6 (limit: 4679)
     Memory: 12.4M
        CPU: 108ms
     CGroup: /system.slice/apache2.service
             ??55486 /usr/sbin/apache2 -k start
             ??55487 /usr/sbin/apache2 -k start
             ??55488 /usr/sbin/apache2 -k start
             ??55489 /usr/sbin/apache2 -k start
             ??55490 /usr/sbin/apache2 -k start
             ??55491 /usr/sbin/apache2 -k start

Mar 06 06:33:24 debian11 systemd[1]: Starting The Apache HTTP Server...
Mar 06 06:33:24 debian11 apachectl[55485]: AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 209>
Mar 06 06:33:24 debian11 systemd[1]: Started The Apache HTTP Server.

访问 Matomo 网页界面

现在,打开您的网络浏览器并使用 URL http://matomo.example.com 访问 Matomo 网络界面。您将被重定向到以下页面:

单击下一步按钮。您应该会看到 PHP 配置检查页面:

确保所有配置都正确,然后单击 NEXT 按钮。您应该会看到 MariaDB 数据库设置页面:

提供您的数据库服务器、用户名、数据库名称、密码,然后单击“下一步”按钮。您应该会看到以下页面:

单击“下一步”按钮。您应该看到超级用户创建页面:

提供您的管理员用户名、密码、电子邮件,然后单击“下一步”按钮。您应该看到网站设置页面:

提供您的网站名称、URL、时区,然后单击下一步按钮。您应该会看到以下页面:

单击“下一步”按钮。您应该会看到配置验证页面:

点击继续 MATOMO。您应该会看到 Matomo 登录页面:

提供您的管理员用户名、密码,然后单击“登录”按钮。您应该在以下页面上看到 Matomo 仪表板: 您现在可以复制上图中显示的跟踪代码并将其粘贴到您网站上的每个页面。

使用 Lets Encrypt SSL 保护 Matomo

接下来,您需要安装 Certbot 客户端来为您的网站安装 Lets Encrypt SSL。您可以使用以下命令安装它:

dnf install epel-release -y dnf install certbot python3-certbot-apache

接下来,使用以下命令为您的 lets 域获取并安装 SSL 证书:

certbot --apache -d matomo.example.com

您将被要求提供您的电子邮件地址并接受服务条款:

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator apache, Installer apache
Enter email address (used for urgent renewal and security notices)
 (Enter 'c' to cancel): 

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server. Do you agree?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing, once your first certificate is successfully issued, to
share your email address with the Electronic Frontier Foundation, a founding
partner of the Let's Encrypt project and the non-profit organization that
develops Certbot? We'd like to send you email about our work encrypting the web,
EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y
Account registered.
Requesting a certificate for matomo.example.com
Performing the following challenges:
http-01 challenge for matomo.example.com
Waiting for verification...
Cleaning up challenges
Deploying Certificate to VirtualHost /etc/httpd/conf.d/matomo.conf
Redirecting all traffic on port 80 to ssl in /etc/httpd/conf.d/matomo.conf

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled https://matomo.example.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Subscribe to the EFF mailing list (email: ).


IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/matomo.example.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/matomo.example.com/privkey.pem
   Your certificate will expire on 2022-05-09. To obtain a new or
   tweaked version of this certificate in the future, simply run
   certbot again with the "certonly" option. To non-interactively
   renew *all* of your certificates, run "certbot renew"
 - If you like Certbot, please consider supporting our work by:

   Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
   Donating to EFF:                    https://eff.org/donate-le

结论

恭喜!您已经在 Debian 11 上成功安装了 Matomo。您现在可以将跟踪代码添加到您的网站并开始从 Matomo 仪表板监控它。如果您有任何问题,请随时问我。

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