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

加载更多搜索结果...

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

如何在 Ubuntu 18.04 LTS 上安装 Matomo Web Analytics

Matomo 以前称为 Piwik 是一款免费的网络分析应用程序,可用于跟踪对一个或多个网站的在线访问,并显示这些访问的报告以供分析。 Matomo 具有许多功能,包括 Google AdWords、Facebook 广告、Yahoo!搜索营销、跟踪和报告 API、每次点击费用 (CPC) 等等。

在本教程中,我将解释如何在 Ubuntu 18.04 LTS 服务器上安装 Matomo。

要求

  • 运行 Ubuntu 18.04 LTS 的服务器。
  • 具有 sudo 权限的非 root 用户。

安装 LAMP 服务器

Matomo 运行在 Web 服务器上,用 PHP 语言编写,并使用 MariaDB 来存储数据。因此,您需要在系统中安装 Apache、MariaDB、PHP 和其他所需的 PHP 模块。

使用以下命令更新 Ubuntu 存储库并安装 PHP 以及 Apache 和 MariaDB:

sudo apt-get update -y
sudo apt-get install apache2 mariadb-server php7.2 libapache2-mod-php7.2 php7.2-common php7.2-sqlite php7.2-curl php7.2-intl php7.2-mbstring php7.2-xmlrpc php7.2-mysql php7.2-gd php7.2-xml php7.2-cli php7.2-zip wget unzip git -y

安装所有软件包后,启动 Apache 和 MariaDB 服务,并使用以下命令使它们在启动时启动:

sudo systemctl start apache2
sudo systemctl enable apache2
sudo systemctl start mariadb
sudo systemctl enable mariadb

接下来,您需要修改 php.ini 文件。您可以使用以下命令来执行此操作:

sudo nano /etc/php/7.2/apache2/php.ini

进行以下更改:

memory_limit = 256M
upload_max_filesize = 200M
max_execution_time = 360
date.timezone = Europe/Berlin

完成后保存并关闭文件。

配置 MariaDB

接下来,您需要保护 MariaDB 安装的安全。您可以通过运行以下脚本来完成此操作:

sudo mysql_secure_installation

回答所有问题,如下所示:

    Enter current password for root (enter for none):
    Set root password? [Y/n]: N
    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 受到保护,请登录 MariaDB shell:

mysql -u root

使用以下命令创建数据库和用户:

MariaDB [(none)]> CREATE DATABASE matomodb;
MariaDB [(none)]> CREATE USER matomo;

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

MariaDB [(none)]> GRANT ALL PRIVILEGES ON matomodb.* TO 'matomo'@'localhost' IDENTIFIED BY 'mypassword';

将“mypassword”一词替换为您选择的安全密码。接下来,使用以下命令刷新权限:

MariaDB [(none)]> FLUSH PRIVILEGES;

接下来,使用以下命令退出 MariaDB 控制台:

MariaDB [(none)]> exit

安装Matomo

首先,从官方网站下载最新版本的 Matomo 到 /tmp 目录:

cd /tmp
wget https://builds.matomo.org/piwik.zip

接下来,使用以下命令解压缩下载的文件:

unzip piwik.zip

然后将解压后的目录复制到Apache根目录并赋予适当的权限:

sudo cp -r piwik /var/www/html/matomo
sudo chown -R www-data:www-data /var/www/html/matomo/
sudo chmod -R 755 /var/www/html/matomo/

最后,使用以下命令为 Matomo 创建 Apache 配置文件:

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

添加以下行:

<VirtualHost *:80>
     ServerAdmin [email 
     DocumentRoot /var/www/html/matomo
     ServerName example.com

     <Directory /var/www/html/matomo/>
          Options FollowSymlinks
          AllowOverride All
          Require all granted
     </Directory>

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

</VirtualHost>

将 example.com 和电子邮件地址 [email 替换为您自己的域名和电子邮件地址。保存并关闭文件,然后使用以下命令启用虚拟主机文件和 Apache 重写模块:

sudo a2ensite matomo
sudo a2enmod rewrite

重新启动 Apache Web 服务以应用所有更改:

sudo systemctl restart apache2

通过 Let's encrypt 为 Matomo 启用 SSL

在此步骤中,我们将使用免费的 Let's encrypt SSL 证书为 Matomo 启用 SSL。第一步是安装 certbot Let's encrypt 客户端,我们将使用它来获取 SSL 证书。

sudo apt-get install certbot python-certbot-apache

使用以下命令请求 SSL 证书:

sudo certbot --apache

重要提示:您用于 RoundCube 网站的域名或子域必须可通过互联网访问才能获取 SSL 证书。 Certbot 现在会问几个问题。

root@server: certbot --apache
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): [email 
-------------------------------------------------------------------------------
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 at
https://acme-v01.api.letsencrypt.org/directory
-------------------------------------------------------------------------------
(A)gree/(C)ancel: a
-------------------------------------------------------------------------------
Would you be willing 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 EFF and
our work to encrypt the web, protect its users and defend digital rights.
-------------------------------------------------------------------------------
(Y)es/(N)o: n
Which names would you like to activate HTTPS for?
-------------------------------------------------------------------------------
1: example.com
-------------------------------------------------------------------------------
Select the appropriate numbers separated by commas and/or spaces, or leave input
blank to select all options shown (Enter 'c' to cancel): 1
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for example.com
Waiting for verification...
Cleaning up challenges
Created an SSL vhost at /etc/apache2/sites-available/matomo-le-ssl.conf
Enabled Apache socache_shmcb module
Enabled Apache ssl module
Deploying Certificate to VirtualHost /etc/apache2/sites-available/matomo-le-ssl.conf
Enabling available site: /etc/apache2/sites-available/matomo-le-ssl.conf
Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
-------------------------------------------------------------------------------
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
-------------------------------------------------------------------------------
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2
Redirecting vhost in /etc/apache2/sites-enabled/matomo.conf to ssl vhost in /etc/apache2/sites-available/matomo-le-ssl.conf
-------------------------------------------------------------------------------
Congratulations! You have successfully enabled https://example.com
You should test your configuration at:
https://www.ssllabs.com/ssltest/analyze.html?d=example.com
-------------------------------------------------------------------------------
IMPORTANT NOTES:
- Congratulations! Your certificate and chain have been saved at:
/etc/letsencrypt/live/example.com/fullchain.pem
Your key file has been saved at:
/etc/letsencrypt/live/example.com/privkey.pem
Your cert will expire on 2019-07-10. 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"
- Your account credentials have been saved in your Certbot
configuration directory at /etc/letsencrypt. You should make a
secure backup of this folder now. This configuration directory will
also contain certificates and private keys obtained by Certbot so
making regular backups of this folder is ideal.
- 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

Matomo 虚拟主机现在可以通过 https 访问。

访问马托莫

现在,打开您的网络浏览器并输入 URL https://example.com,您将被重定向到 Matomo 欢迎页面:

现在,单击下一步按钮。您应该看到以下页面:

在这里,确保所有必需的模块都已安装。然后,单击下一步按钮。您应该看到以下页面:

在这里,提供您的 Matomo 数据库和用户名。然后,单击下一步按钮。您应该看到以下页面:

现在,单击下一步按钮。您应该看到以下页面:

在这里,提供您的管理员用户名和密码。然后,单击下一步按钮。您应该看到以下页面:

现在,提供网站名称、网站 URL。然后,单击下一步按钮。您应该在以下页面中看到 Matomo 网站的跟踪代码:

现在,单击下一步按钮。安装完成后。您应该看到以下页面:

现在,点击继续 MATOMO 按钮。您应该看到以下页面:

现在,提供管理员登录凭据并单击登录按钮。您应该在以下页面中看到 Matomo 仪表板:

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