跳转至

matomo安装及配置

matomo是一个类似于Google analytics的网站访问统计的服务,基于PHP+Mysql。网站一直没有使用访问统计,写的东西到底有没有人看、主要关注哪些文章都无从知晓,所有还是准备添加上访问统计。
以前使用过Google analytics,也使用过国内的比较小众的网站的。Google的由于访问受限,不再考虑,国内百度之流更不能考虑,国内小众网站的服务总感觉不怎么爽。另外,目去的去广告扩展默认将以上所提到的统计代码都给屏蔽掉了。由于自己买的是服务器,那么完全可以自己跑一个这类的服务,正好GitHub上有开源的项目。又由于服务器其它服务使用了LNMP环境,所以就选择了matomo,顺便还解决了去广告扩展屏蔽的问题。

安装

安装LNMP环境

由于是基于PHP+Mysql,所以第一步是配置LNMP环境。 请参考这篇文章
LNMP安装完成后,新建nginx的配置文件/etc/nginx/sites-enabled/web.zimoapps.com.conf

vi /etc/nginx/sites-enabled/web.zimoapps.com.conf

并粘贴以下内容后保存退出1

server {
        server_name web.zimoapps.com;
        listen 80;
        listen [::]:80;
        return 301 https://$server_name$request_uri;
}
server {
        server_name web.zimoapps.com;
        root /var/www/web.zimoapps.com;
        listen 443      ssl http2;
        listen [::]:443 ssl http2;
        index index.php index.html index.htm;
        ssl_certificate     /etc/letsencrypt/live/zimoapps.com/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/zimoapps.com/privkey.pem;
        location ~ \.php$ {
                fastcgi_index index.php;
                fastcgi_param  SCRIPT_FILENAME $request_filename;
                fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
                include fastcgi_params;
        }
}

以上供参考,其中的域名、PHP-fpm路径、证书路径等信息,根据实际情况做响应修改。保存配置文件后,还需要让ningx重新载入配置2使这个新的配置立即生效。

安装motomo

新建网站的目录(配置文件中的root所对应的目录)``

准备安装包

使用GIT

在服务器上可以使用git clone得到安装包:

cd /var/www/
git clone https://github.com/matomo-org/matomo web.zimoapps.com
直接下载最新版的压缩包

git clone 的文件较大,加上服务器连接GitHub速度较慢,所以使用的是直接下载安装包的形式。 可以服务器wget下载,也可以本地下载后上传到服务器:

cd /var/www/
wget https://github.com/matomo-org/matomo/archive/4.1.2-rc1.zip

解压下载完成后的压缩包4.1.2-rc1.zip,会得到文件夹matomo-4.1.2-rc1,将其重命名为web.zimoapps.com

注意

上述操作完成后,所有的文件存放在目录/var/www/web.zimoapps.com中,这个目录与nginx配置文件中的root的值相对应。

完成安装

最后,修改web.zimoapps.com的权限即所属:

chmod -R 777 /var/www/web.zimoapps.com
chown -R www-data:www-data /var/www/web.zimoapps.com

现在,通过浏览器访问我们的域名web.zimoapps.com,根据提示,填入mysql地址、端口、账号密码及数据库名称等信息后就可以顺利完成安装。

提示

安装过程中可能会提示以下错误:

It appears the composer tool is not yet installed. You can install Composer in a few easy steps:
In the matomo directory, run in the command line the following (eg. via ssh):

curl -sS https://getcomposer.org/installer | php 

php composer.phar install
根据提示,完成安装即可:
curl -sS https://getcomposer.org/installer | php 
php composer.phar install

遇到的问题

icon图片不显示

后台可能会像下图所示,部分icon不能显示,单独打开这些icon则显示404。

根据这个issue的描述,问题出在matomo还关联了另外个项目matomo-icons。解决办法是,将matomo-icons的所有文件放置到/var/www/web.zimoapps.com/plugins/Morpheus/icons目录下:

cd /var/www/web.zimoapps.com/plugins/Morpheus
rm -rf icons
git clone  https://github.com/matomo-org/matomo-icons.git icons

浏览器再次打开,应该就能正常显示icon图片了。最后,看看效果:


  1. vim保存退出操作如下:先 ++esc++ ,再输入":wq",然后 ++enter++ 。 

  2. nginx重新载入配置命令:

    nginx -s reload