Matomo,以前称为Piwik,是一款开源网络分析软件,可让您跟踪和分析网站的访问者及其行为。它可用于跟踪网站访问者,跟踪网站上的用户交互,并生成有关网站流量,搜索引擎优化和转化率优化的报告。Matomo是用PHP编写的,并使用MySQL / MariaDB数据库来存储数据。
在 Ubuntu 22.04 LTS Jammy Jellyfish 上安装 Matomo
第 1 步。首先,通过在终端中运行以下命令,确保所有系统软件包都是最新的。apt
<span class="pln">sudo apt update sudo apt upgrade</span>
第 2 步。在 Ubuntu 22.04 上安装 LAMP 堆栈。
在开始本教程之前,必须在服务器上安装 LAMP 服务器。如果您没有安装 LAMP 堆栈,您可以按照我们的指南进行操作。
第 3 步。在 Ubuntu 22.04 上安装 Matomo Web Analytics。
默认情况下,Matomo 在 Ubuntu 22.04 基本存储库中不可用。现在运行以下命令,从 Ubuntu 系统的官方页面下载最新的稳定版 Matomo:
<span class="pln">cd </span><span class="pun">/</span><span class="kwd">var</span><span class="pun">/</span><span class="pln">www</span><span class="pun">/</span><span class="pln"> wget https</span><span class="pun">:</span><span class="com">//builds.matomo.org/matomo.zip</span>
接下来,解压缩下载的文件:
<span class="pln">unzip matomo</span><span class="pun">.</span><span class="pln">zip</span>
我们需要更改一些文件夹权限:
<span class="pln">sudo chown </span><span class="pun">-</span><span class="pln">R www</span><span class="pun">-</span><span class="pln">data</span><span class="pun">:</span><span class="pln">www</span><span class="pun">-</span><span class="pln">data </span><span class="pun">/</span><span class="kwd">var</span><span class="pun">/</span><span class="pln">www</span><span class="pun">/</span><span class="pln">matomo</span>
第 4 步。配置 MariaDB。
默认情况下,MariaDB 未强化。您可以使用脚本保护 MariaDB。您应该仔细阅读并在每个步骤下方仔细阅读,这将设置root密码,删除匿名用户,禁止远程root登录,并删除测试数据库和对安全MariaDB的访问权限:mysql_secure_installation
<span class="pln">mysql_secure_installation</span>
像这样配置它:
<span class="pun">-</span> <span class="typ">Set</span><span class="pln"> root password</span><span class="pun">?</span> <span class="pun">[</span><span class="pln">Y</span><span class="pun">/</span><span class="pln">n</span><span class="pun">]</span><span class="pln"> y </span><span class="pun">-</span> <span class="typ">Remove</span><span class="pln"> anonymous users</span><span class="pun">?</span> <span class="pun">[</span><span class="pln">Y</span><span class="pun">/</span><span class="pln">n</span><span class="pun">]</span><span class="pln"> y </span><span class="pun">-</span> <span class="typ">Disallow</span><span class="pln"> root login remotely</span><span class="pun">?</span> <span class="pun">[</span><span class="pln">Y</span><span class="pun">/</span><span class="pln">n</span><span class="pun">]</span><span class="pln"> y </span><span class="pun">-</span> <span class="typ">Remove</span><span class="pln"> test database </span><span class="kwd">and</span><span class="pln"> access to it</span><span class="pun">?</span> <span class="pun">[</span><span class="pln">Y</span><span class="pun">/</span><span class="pln">n</span><span class="pun">]</span><span class="pln"> y </span><span class="pun">-</span> <span class="typ">Reload</span><span class="pln"> privilege tables now</span><span class="pun">?</span> <span class="pun">[</span><span class="pln">Y</span><span class="pun">/</span><span class="pln">n</span><span class="pun">]</span><span class="pln"> y</span>
接下来,我们需要登录 MariaDB 控制台并为 Matomo 创建一个数据库。运行以下命令:
<span class="pln">mysql </span><span class="pun">-</span><span class="pln">u root </span><span class="pun">-</span><span class="pln">p</span>
这将提示您输入密码,因此请输入您的MariaDB root密码并按Enter键。登录到数据库服务器后,您需要为Matomo安装创建一个数据库:
<span class="typ">MariaDB</span> <span class="pun">[(</span><span class="pln">none</span><span class="pun">)]></span><span class="pln"> CREATE DATABASE matomo</span><span class="pun">;</span> <span class="typ">MariaDB</span> <span class="pun">[(</span><span class="pln">none</span><span class="pun">)]></span><span class="pln"> CREATE USER </span><span class="str">'matomo'</span><span class="pun">@</span><span class="str">'localhost'</span><span class="pln"> IDENTIFIED BY </span><span class="str">'your-strong-passwd'</span><span class="pun">;</span> <span class="typ">MariaDB</span> <span class="pun">[(</span><span class="pln">none</span><span class="pun">)]></span><span class="pln"> GRANT SELECT</span><span class="pun">,</span><span class="pln"> INSERT</span><span class="pun">,</span><span class="pln"> UPDATE</span><span class="pun">,</span><span class="pln"> DELETE</span><span class="pun">,</span><span class="pln"> CREATE</span><span class="pun">,</span><span class="pln"> INDEX</span><span class="pun">,</span><span class="pln"> DROP</span><span class="pun">,</span><span class="pln"> ALTER</span><span class="pun">,</span><span class="pln"> CREATE TEMPORARY TABLES</span><span class="pun">,</span><span class="pln"> LOCK TABLES ON matomo</span><span class="pun">.*</span><span class="pln"> TO </span><span class="str">'matomo'</span><span class="pun">@</span><span class="str">'localhost'</span><span class="pun">;</span> <span class="typ">MariaDB</span> <span class="pun">[(</span><span class="pln">none</span><span class="pun">)]></span><span class="pln"> FLUSH PRIVILEGES</span><span class="pun">;</span> <span class="typ">MariaDB</span> <span class="pun">[(</span><span class="pln">none</span><span class="pun">)]></span><span class="pln"> EXIT</span><span class="pun">;</span>
有关安装和管理 MariaDB 的其他资源,请阅读下面的帖子:
- 如何在 Ubuntu Linux √ 上安装 MariaDB
第5步。配置 Apache 虚拟主机。
现在为 Matomo 创建虚拟主机配置文件:
<span class="pln">sudo nano </span><span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="pln">apache2</span><span class="pun">/</span><span class="pln">sites</span><span class="pun">-</span><span class="pln">available</span><span class="pun">/</span><span class="pln">matomo</span><span class="pun">.</span><span class="pln">conf</span>
添加以下文件:
<span class="tag"><VirtualHost</span><span class="pln"> *:80</span><span class="tag">></span><span class="pln"> ServerAdmin admin@your-domain.com ServerName analytics.your-domain.com DocumentRoot /var/www/matomo/ </span><span class="tag"><Directory</span> <span class="pun">/</span><span class="atn">var</span><span class="pun">/</span><span class="atn">www</span><span class="pun">/</span><span class="atn">matomo</span><span class="tag">></span><span class="pln"> DirectoryIndex index.php Options FollowSymLinks AllowOverride All Require all granted </span><span class="tag"></Directory></span><span class="pln"> </span><span class="tag"><Files</span> <span class="atv">"console"</span><span class="tag">></span><span class="pln"> Options None Require all denied </span><span class="tag"></Files></span><span class="pln"> </span><span class="tag"><Directory</span> <span class="pun">/</span><span class="atn">var</span><span class="pun">/</span><span class="atn">www</span><span class="pun">/</span><span class="atn">matomo</span><span class="pun">/</span><span class="atn">misc</span><span class="pun">/</span><span class="atn">user</span><span class="tag">></span><span class="pln"> Options None Require all granted </span><span class="tag"></Directory></span><span class="pln"> </span><span class="tag"><Directory</span> <span class="pun">/</span><span class="atn">var</span><span class="pun">/</span><span class="atn">www</span><span class="pun">/</span><span class="atn">matomo</span><span class="pun">/</span><span class="atn">misc</span><span class="tag">></span><span class="pln"> Options None Require all denied </span><span class="tag"></Directory></span><span class="pln"> </span><span class="tag"><Directory</span> <span class="pun">/</span><span class="atn">var</span><span class="pun">/</span><span class="atn">www</span><span class="pun">/</span><span class="atn">matomo</span><span class="pun">/</span><span class="atn">vendor</span><span class="tag">></span><span class="pln"> Options None Require all denied </span><span class="tag"></Directory></span><span class="pln"> ErrorLog ${APACHE_LOG_DIR}/matomo_error.log CustomLog ${APACHE_LOG_DIR}/matomo_access.log combined </span><span class="tag"></VirtualHost></span>
保存并关闭文件,然后重新启动 Apache Web 服务器,以便进行更改:
<span class="pln">sudo a2ensite matomo</span><span class="pun">.</span><span class="pln">conf sudo a2enmod rewrite sudo systemctl restart apache2</span>
有关安装和管理 Apache 的其他资源,请阅读下面的帖子:
- 如何在 Ubuntu Linux √ 上安装 Apache。
第 6 步。使用Let’s Encrypt SSL保护Matomo。
首先,使用以下命令安装 Certbot 客户端:
<span class="pln">sudo apt install certbot python3</span><span class="pun">-</span><span class="pln">certbot</span><span class="pun">-</span><span class="pln">apache2</span>
接下来,按照以下步骤使用Let’s Encrypt获取SSL证书:
<span class="pln">certbot </span><span class="pun">--</span><span class="pln">apache </span><span class="pun">-</span><span class="pln">d analytics</span><span class="pun">.</span><span class="pln">your</span><span class="pun">-</span><span class="pln">domain</span><span class="pun">.</span><span class="pln">com</span>
让我们加密证书的有效期为 90 天,强烈建议在证书过期之前续订证书。您可以通过运行以下命令来测试证书的自动续订:
<span class="pln">sudo certbot renew </span><span class="pun">--</span><span class="pln">dry</span><span class="pun">-</span><span class="pln">run</span>
步骤 7.配置防火墙。
现在我们使用Apache设置了一个简单防火墙(UFW),以允许在HTTP和HTTPS的默认Web端口上进行公共访问:
<span class="pln">sudo ufw allow </span><span class="typ">OpenSSH</span><span class="pln"> sudo ufw allow </span><span class="str">'Apache Full'</span><span class="pln"> sudo ufw enable</span>
第8步。访问 Matomo 网络分析网络界面。
成功安装后,打开您的网络浏览器并使用 URL 访问 Matomo 网络 UI。您将被重定向到以下页面:https://analytics.your-domain.com
感谢您使用本教程在 Ubuntu 22.04 LTS Jammy Jellyfish 系统上安装 Matomo Web Analytics。如需更多帮助或有用信息,我们建议您查看 Matomo 网站。