当前位置: 首页>>技术教程>>正文


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

,

Matomo(以前称为Piwik)是一种免费的网络分析应用程序,可用于跟踪对一个或多个网站的在线访问,并显示这些访问的报告以进行分析。 Matomo具有许多功能,包括Google AdWords,Facebook Ads,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 admin@example.com
     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和电子邮件地址admin@example.com。保存并关闭文件,然后使用以下命令启用虚拟主机文件和Apache重写模块:

sudo a2ensite matomo
sudo a2enmod rewrite

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

sudo systemctl restart apache2

通过“为Matomo加密”启用SSL

在这一步中,我们将使用免费的“加密” SSL证书为Matomo启用SSL。第一步是安装certbot让我们加密客户端,我们将使用它来获取SSL证书。

sudo apt-get install certbot python-certbot-apache

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

sudo certbot --apache

重要说明:您必须从Internet上访问用于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): youremail@yourdomain.tld
-------------------------------------------------------------------------------
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虚拟主机。

进入Matomo

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

Welcome to Matomo installer

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

Matomo System Check

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

Database setup

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

Creating Database Tables

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

Add Super User

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

Setup a Website in Matomo

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

Site code

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

Matomo has been successfully installed

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

Matomo Login

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

Matomo Dashboard

参考资料

本文由Ubuntu问答整理, 博文地址: https://ubuntuqa.com/article/8243.html,未经允许,请勿转载。