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

[ad_1]

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

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

要求

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

安装 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

Save 和 close 文件,完成后。

配置 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/

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

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

添加以下行:

<VirtualHost *:80>
     ServerAdmin [email protected]
     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 protected] 使用您自己的域名和电子邮件地址。 Save 和 close 该文件,然后启用虚拟主机文件和 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 让我们加密客户端,我们将使用它来获取 SSL 证书。

sudo apt-get install certbot python-certbot-apache

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

sudo certbot --apache

重要提示:您用于 RoundCube 网站的域名或子域必须可从 Internet 访问以获得 SSL 证书。 Certbot 现在会问几个问题。

[email protected]: 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 protected]
-------------------------------------------------------------------------------
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

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

访问间友

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

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

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

数据库设置

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

创建数据库表

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

添加超级用户

在这里,提供您的 admin 用户名和密码。 然后,点击 下一个 按钮。 您应该看到以下页面:

在 Matomo 中建立网站

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

网站代码

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

Matomo 已成功安装

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

登录

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

Matomo 仪表板

[ad_2]

Related Posts