CentOS 7.7搭建LNMP環境部署WordPress,並使用Matomo監控

WordPress是一款使用PHP語言開發的博客平臺,官網https://cn.wordpress.org/
javascript

Matomo的前身是Piwik,一套基於PHP + MySQL技術構建的開源網站訪問統計系統,Matomo能夠提供統計網頁瀏覽人數、訪問最多的頁面、搜索引擎關鍵詞等流量分析功能,它還採用了插件擴展及開放API架構,可讓用戶根據自已的實際需求建立更多的功能,軟件包下載和部署文檔地址https://matomo.org/docs/installation/php

1、安裝配置Nginxhtml

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

二、安裝Nginx# yum -y install nginxmysql

三、啓動Nginxnginx

# systemctl start nginxweb

# systemctl status nginxsql

# ss -tunlp | grep -w :80數據庫

# systemctl enable nginxapache

四、瀏覽器訪問:http://192.168.0.122

image.png


2、安裝配置MariaDB

CentOS 7.7默認yum源中的MariaDB版本爲5.5.64,此處安裝MariaDB 10.4版本

一、查看系統中是否已經存在MariaDB,有則刪除:

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

# yum -y remove mariadb-libs

二、配置MariaDByum源:

# 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

三、安裝MariaDB# yum -y install MariaDB-server

四、修改配置文件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

五、建立錯誤日誌文件:

# touch /var/log/mariadb.log

# chown mysql.mysql /var/log/mariadb.log

六、啓動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

七、MariaDB安全配置嚮導:# mysql_secure_installation

八、受權用戶遠程登陸:

# mysql -uroot -p

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

MariaDB [(none)]> flush privileges;

image.png

九、建立wordpressmatomo數據庫:

MariaDB [(none)]> create database wordpress;

MariaDB [(none)]> create database matomo;

十、建立新用戶,並對其賦予數據庫權限:

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;


3、安裝配置PHP

一、安裝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

二、修改www.conf配置文件:

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

user = apache --> user = nginx

group = apache --> group = nginx

三、啓動php-fpm

# systemctl start php-fpm.service

# systemctl status php-fpm.service

# ss -tunlp | grep 9000

# systemctl enable php-fpm.service


4、Nginx整合PHP

一、修改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

二、建立測試頁:

# 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數據庫。

三、瀏覽器訪問http://192.168.0.122

image.png

中止MariaDB# systemctl stop mariadb.service

刷新頁面:

image.png


5、安裝配置WordPress

一、解壓WordPress# tar -xf wordpress-5.2.4-zh_CN.tar.gz -C /usr/share/nginx/html/

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

# cd /usr/share/nginx/html/wordpress

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

# vim wp-config.php

image.png

三、瀏覽器訪問http://192.168.0.122/wordpress

image.png

image.png

image.png

image.png

image.png


6、安裝配置Matomo

一、解壓Matomo

# yum -y install unzip

# unzip -q matomo.zip

# mv matomo/* /usr/share/nginx/html/

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

二、瀏覽器訪問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


7、WordPress安裝配置Matomo插件:

一、安裝啓用插件:

image.png

image.png

二、配置插件:

image.png

image.png

上述認證令牌(Auth Token)的值來源於:Matomo網站 --> 右上角管理 --> 左側API

image.png

image.png

image.png

image.png

三、查看統計數據:

同時多開幾個瀏覽器訪問http://192.168.0.122/wordpress/,並刷新

image.png

image.png

image.png

image.png

相關文章
相關標籤/搜索