微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

CentOS 7.7搭建LNMP环境部署WordPress,并使用Matomo监控

wordpress是一款使用PHP语言开发的博客平台,官网https://cn.wordpress.org/

matomo的前身是Piwik,一套基于PHP + MysqL技术构建的开源网站访问统计系统,matomo可以提供统计网页浏览人数、访问最多的页面搜索引擎关键词等流量分析功能,它还采用了插件扩展及开放API架构,可以让用户根据自已的实际需求创建更多的功能,软件包下载和部署文档地址https://matomo.org/docs/installation/

一、安装配置Nginx

1、安装epel源:# rpm -ivh https://mirrors.tuna.tsinghua.edu.cn/epel/epel-release-latest-7.noarch.rpm

2、安装Nginx:# yum -y install Nginx

3、启动Nginx

# systemctl start Nginx

# systemctl status Nginx

# ss -tunlp | grep -w :80

# systemctl enable Nginx

4、浏览器访问:http://192.168.0.122

image.png


二、安装配置MariaDB:

CentOS 7.7yum源中的MariaDB版本为5.5.64,此处安装MariaDB 10.4版本

1、查看系统中是否已经存在MariaDB,有则删除

# rpm -qa | grep -i mariadb --> mariadb-libs-5.5.64-1.el7.x86_64

# yum -y remove mariadb-libs

2、配置MariaDB的yum源:

# vim /etc/yum.repos.d/MariaDB.repo

[mariadb]

name=MariaDB Repo

baseurl=http://mirrors.ustc.edu.cn/mariadb/yum/10.4/centos7-amd64/

gpgkey=http://mirrors.ustc.edu.cn/mariadb/yum/RPM-GPG-KEY-MariaDB

enabled=1

gpgcheck=1

3、安装MariaDB:# yum -y install MariaDB-server

4、修改配置文件server.cnf:

# cd /etc/my.cnf.d

# mv server.cnf server.cnf.bak

# vim server.cnf

[MysqLd]

port=3306

socket=/var/lib/MysqL/MysqL.sock

datadir=/var/lib/MysqL

log-error=/var/log/mariadb.log

lower_case_table_names=1

character-set-server=utf8mb4

collation-server=utf8mb4_general_ci

symbolic-links=0

innodb_file_per_table=1

skip_name_resolve=1

slow_query_log=1

slow_query_log_file=MysqL-slow.log

server_id=1

sync_binlog=1

innodb_flush_log_at_trx_commit=1

log_bin=MysqL-bin

log_bin_index=MysqL-bin.index

binlog_format=row

备注:认主配置文件不是/etc/my.cnf,而是/etc/my.cnf.d/server.cnf

5、创建错误日志文件

# touch /var/log/mariadb.log

# chown MysqL.MysqL /var/log/mariadb.log

6、启动MariaDB:

# systemctl start mariadb.service

# systemctl status mariadb.service

# ss -tunlp | grep -w :3306

# tail -100 /var/log/mariadb.log

# tail -100 /var/log/messages

# systemctl enable mariadb.service

7、MariaDB安全配置向导:# MysqL_secure_installation

8、授权用户远程登录

# MysqL -uroot -p

MariaDB [(none)]> grant all on *.* to 'root'@'192.168.0.%' identified by '123456';

MariaDB [(none)]> flush privileges;

image.png

9、创建wordpressmatomo数据库

MariaDB [(none)]> create database wordpress;

MariaDB [(none)]> create database matomo;

10、创建新用户,并对其赋予数据库权限:

MariaDB [(none)]> create user 'wpuser'@'192.168.0.%' identified by '123456';

MariaDB [(none)]> grant all on wordpress.* to 'wpuser'@'192.168.0.%';

MariaDB [(none)]> create user 'mtuser'@'192.168.0.%' identified by '123456';

MariaDB [(none)]> grant all on matomo.* to 'mtuser'@'192.168.0.%';

MariaDB [(none)]> flush privileges;


三、安装配置PHP

1、安装PHP

# rpm -ivh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

# yum -y install mod_PHP72w PHP72w-cli PHP72w-common PHP72w-devel PHP72w-fpm PHP72w-gd PHP72w-ldap PHP72w-mbstring PHP72w-MysqLnd PHP72w-opcache PHP72w-xml

# PHP -version

image.png

2、修改www.conf配置文件

# vim /etc/PHP-fpm.d/www.conf

user = apache --> user = Nginx

group = apache --> group = Nginx

3、启动PHP-fpm:

# systemctl start PHP-fpm.service

# systemctl status PHP-fpm.service

# ss -tunlp | grep 9000

# systemctl enable PHP-fpm.service


四、Nginx整合PHP

1、修改Nginx.conf配置文件

# vim /etc/Nginx/Nginx.conf

location / {

root   html;

index  index.PHP index.html index.htm;

}

location ~ \.PHP$ {

fastcgi_pass   127.0.0.1:9000;

fastcgi_index  index.PHP;

fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

include       fastcgi_params;

}

# Nginx -t

# Nginx -s reload

2、创建测试页:

# vim /usr/share/Nginx/html/index.PHP

<?PHP

$conn=MysqLi_connect("192.168.0.122","root","123456");

if ($conn)

echo "MysqLi_connect success";

else

echo "MysqLi_connect failure";

MysqLi_close();

PHPinfo();

?>

备注:如果在新版本PHP中使用旧版本PHPMysqL_connect()函数连接MysqL,会提示undefined function MysqL_connect()”。从PHP 5.5版本开始,MysqL就不推荐使用MysqL_connect()函数,属于废弃函数PHP 7中已经彻底不支持增加MysqLi_connect()函数。从某种意义上说,MysqLiMysqL系统函数的增强版,更稳定、更高效、更安全,属于面向对象,用对象的方式操作驱动MysqL数据库

3、浏览器访问http://192.168.0.122

image.png

停止MariaDB# systemctl stop mariadb.service

刷新页面

image.png


五、安装配置wordpress

1、解压wordpress:# tar -xf wordpress-5.2.4-zh_CN.tar.gz -C /usr/share/Nginx/html/

2、修改wp-config.php配置文件

# cd /usr/share/Nginx/html/wordpress

# cp wp-config-sample.PHP wp-config.php

# vim wp-config.php

image.png

3、浏览器访问http://192.168.0.122/wordpress

image.png

image.png

image.png

image.png

image.png


六、安装配置matomo

1、解压matomo

# yum -y install unzip

# unzip -q matomo.zip

# mv matomo /usr/share/Nginx/html/

# chown -R Nginx.Nginx /usr/share/Nginx/html

2、浏览器访问http://192.168.0.122/matomo

image.png

image.png

除了“强制SSL连接”,其它都要通过检查:

image.png

image.png

image.png

image.png

image.png

image.png

<!-- matomo -->

<script type="text/javascript">

  var _paq = window._paq || [];

  /* tracker methods like "setCustomDimension" should be called before "trackPageView" */

  _paq.push(['trackPageView']);

  _paq.push(['enableLinkTracking']);

  (function() {

    var u="//192.168.0.122/matomo/";

    _paq.push(['setTrackerUrl', u+'matomo.PHP']);

    _paq.push(['setSiteId', '1']);

    var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];

    g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);

  })();

</script>

<!-- End matomo Code -->

image.png

image.png

没有任何数据:

image.png


七、wordpress安装配置matomo插件

1、安装启用插件

image.png

image.png

2、配置插件

image.png

image.png

上述认证令牌(Auth Token)的值来源于:matomo网站 --> 右上角管理 --> 左侧API

image.png

image.png

image.png

image.png

3、查看统计数据:

同时多开几个浏览器访问http://192.168.0.122/wordpress/,并刷新

image.png

image.png

image.png

image.png


版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐