Matomo搭建一個屬於自己的網站統計分析站點


 

本文介紹matomo(前身Pwiki)的本地搭建過程。matomo作為前端頁面的日志統計工具,對一些網站的監控還是很有必要的。 

 

參考官網的安裝步驟,其中至少需要:

  1. 數據庫(選用 mysql 5.7.24)

  2. nginx代理 (選用 nginx 1.6.3)

  3. php (選用 php 7.2.12)

主機 IP地址 服務
web01 10.0.0.7 wordpress
web02 10.0.0.8 matomo

部署WEB環境安裝Matomo程序

安裝nginx,搭建web頁面

vim /etc/yum.repos.d/nginx.repo    --官方源
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key

[root@web01 ~]# yum install nginx -y 

編輯/etc/nginx/conf.d/blog.conf配置文件

 server {
        listen       80;
        server_name  blog.oldboy.com;
    client_max_body_size 100m;
        location / {
            root   /html;
            index  index.php  index.html index.htm;
        }
        location ~ \.php$ {
            root /html;
            fastcgi_pass  127.0.0.1:9000;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;
        }
    }

創建目錄/html

[root@web01 ~]# mkdir /html
[root@web01 ~]# cd /html
[root@web01 /html]# wget https://builds.matomo.org/matomo.zip   --下載matomo
[root@web01 /html]# unzip matomo-latest.zip
[root@web01 /html]# mv matomo/* /html/       --將文件移動到/html
[root@web01 /html]# chown -R nginx.nginx .

安裝php

網盤鏈接https://pan.baidu.com/s/1l67P0Y4GY_8AHhKXp8mgSQ 提取碼:7vmw

解壓php71w.tar.gz並安裝php (php鏈接地址在上面查找)

[root@web01 ~]# ls 
a  anaconda-ks.cfg  php71w.tar.gz
[root@web01 ~]# cd /a
[root@web01 ~/a]# yum localinstall ./*.rpm -y 
[root@web01 ~/a]# vim /etc/php-fpm.d/www.conf 
-- 修改所屬主和所屬組為nginx
[root@web01 ~/a]# systemctl start php-fpm 
[root@web01 ~/a]# systemctl enable  php-fpm 

部署mariadb

yum install mariadb mariadb-server -y
systemctl start mariadb
systemctl enable mariadb
 
mysql
#創建matomo數據庫
MariaDB [(none)]> create database matomo;
MariaDB [(none)]> grant all on matomo.* to matomo@'10.0.0.%' identified by '123456';

下載matomo

官網地址https://matomo.org/

[root@web01 ~]# mkdir /html
[root@web01 ~]# cd /html
[root@web01 /html]# wget https://builds.matomo.org/matomo.zip 
--解壓文件
[root@web01 /html]# chown  -R nginx.nginx .

登錄地址http://10.0.0.7/index.php

 

安裝說明在/html刪除文件

rm "/html/How to install Matomo.html" "/html/matomo-latest.zip"

設置要統計的網站

將網站js代碼復制下來  注:代碼唯一

創建wordpress網站

wordpress官網https://wordpress.org/

網盤鏈接https://pan.baidu.com/s/1F59vA1Ux9vh0SqL2x19LUg 提取碼:f5oe

安裝nginx

vim /etc/yum.repos.d/nginx.repo    --官方源
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key

[root@web01 ~]# yum install nginx -y 

編輯/etc/nginx/conf.d/blog.conf配置文件

 server {
        listen       80;
        server_name  10.0.0.8;
    client_max_body_size 100m;
        location / {
            root   /html;
            index  index.php  index.html index.htm;
        }
        location ~ \.php$ {
            root /html;
            fastcgi_pass  127.0.0.1:9000;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;
        }
    }

安裝php

#安裝php71w.tar.gz
[root@web02 ~/a]# yum localinstall ./*.rpm -y

systemctl start php-fpm 
systemctl enable php-fpm

部署mariadb

yum install mariadb mariadb-server -y
systemctl start mariadb
systemctl enable mariadb
mysql

創建blog數據庫

MariaDB [(none)]> create database blog;
MariaDB [(none)]> grant all on blog.* to blog@'10.0.0.%' identified by '123456';

wordpress文件

[root@web02 /html]# unzip wordpress-5.3-zh_CN.zip 
[root@web02 /html]# mv ./wordpress/* /html/ 
[root@web02 /html]# chown -R nginx.nginx .
[root@web02 /html]# systemctl restart nginx

登錄:10.0.0.8/index.php

在站點目錄創建wp-config.php

matomo統計代碼加入到網站

[root@web02 /html/wp-content/themes/twentyseventeen]# vim footer.php 
--將代碼放入</body>上面

登錄matomohttp://10.0.0.7/index.php需要刷新


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM