LNMP|2021最新LNMP => WordPress分离式部署(实战案例)

架构解析

  • Yum安装nginx
  • 配置nginx连接php处理动态请求
  • 安装mariadb数据库
  • php服务器参数配置
  • 服务上传与部署、上线


WordPress分离式部署(实战案例) 简介: WordPress是一种使用PHP语言开发的博客平台,用户可以在支持PHP和MySQL 数据库的服务器上架设自己的网志
环境:Nginx+MySQL服务器 => 192.168.178.6PHP服务器 => 192.168.178.7

Nginx+MySQL服务器 => 192.168.178.6

配置防火墙规则与关闭selinux
1. 关闭selinux:sed -r '/^SELINUX=/c SELINUX=disabled' /etc/selinux/config //永久关闭 setenforce 0//临时关闭防火墙,由于永久关闭要重启,先临时关闭,避免重启 2. 配置firewall规则d:systemctl restart firewalld firewall-cmd --add-service=http --permanent#nginx firewall-cmd --add-service=https --permanent firewall-cmd--add-port=3306/tcp --permanent#mysql firewall-cmd--add-port=9000/tcp --permanent#php firewall-cmd --reload//配置生效 firewall-cmd --list-services//查看是否配置成功

#firewall-cmd可配置或不用配置也行,你可以直接关闭防火墙 systemctl stop firewalld
下方所有的防火墙配置你都可以自行选择
YUM安装nginx
1. 可以在Nginx官网搜索YUM源配置方法:http://nginx.org/en/linux_packages.html#RHEL-CentOS 2. 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 module_hotfixes=true ? 3. 安装nginx: yum -y install nginx

配置接收动态请求 FastCGI模块,连接php
1. vim /etc/nginx/conf.d/default.conf server { location / { root/usr/share/nginx/html; indexindex.php index.html index.htm; #主页优先级!!!!!! } location ~ \.php$ {#连接PHP服务器 root /usr/share/nginx/html; #php存放文件的目录 fastcgi_pass 192.168.178.7:9000; #PHP服务器的地址:端口 !!!!!! fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } }

安装数据库mariadb
简介:CentOS上的MySQL分支数据库,开源,由MySQL前班人马编写,MySQL的替代品,比MySQL兼容性更强。
1. 安装程序:yum -y install mariadb mariadb-server 2. 开启服务: systemctl start mariadbsystemctl enable mariadb 3. 修改数据库密码:mysqladmin password '123456' 4. 创建数据库授权用户:mysql -uroot -p123456 MariaDB [(none)]> create databases bbs; MariaDB [(none)]> grant all on bbs.* to phptest@'192.168.178.7' identified by '123456'; MariaDB [(none)]> flush privileges; MariaDB [(none)]> select user,host from mysql.user; #查看用户是否创建成功


PHP服务器 => 192.168.178.7

配置防火墙规则与关闭selinux
1. 关闭selinux:sed -r '/^SELINUX=/c SELINUX=disabled' /etc/selinux/config //永久关闭 setenforce 0//临时关闭防火墙,由于永久关闭要重启,先临时关闭,避免重启 2. 配置firewalld规则:systemctl restart firewalld firewall-cmd --add-service=http --permanent firewall-cmd --add-service=https --permanent firewall-cmd--add-port=9000/tcp --permanent firewall-cmd--add-port=3306/tcp --permanent firewall-cmd --reload//配置生效 firewall-cmd --list-services//查看是否配置成功

安装php及相关子程序,配置PHP
1. 安装程序:yum -y install php php-fpm php-gd php-mysql 2. 配置php-fpm: vim /etc/php-fpm.d/www.conf # user = nginx; # group = nginx; # listen = 192.168.178.7:9000#PHP服务器的IP地址 !!!!!! # listen.allowed_clients = 192.168.178.6#Nginx的IP地址 如果有多个Nginx(ip1,ip2,ip3) !!!!!! 3. 重启生效: systemctl restart php-fpm 4. 安装nginx(不启动): yum -y install nginx#因为配置文件中用到了nginx用户及组,不用启动,安装即可

安装mariadb客户端,PHP能通过客户端去连接数据库
yum -y install mariadb 测试是否能连接192.168.178.6的数据库: mysql -uphptest -p'123456'-h192.168.178.6 -P3306


WordPress 服务上线 => Nginx+MySQL服务器 :192.168.178.6
百度网盘:
链接:https://pan.baidu.com/s/16Vw4ql-qNKopfwdvAkk1GQ
提取码:help
1. 上传压缩包进行解压:yum -y install unzip unzip wordpress-4.9.1-zh_CN.zip 2. 上传代码至Nginx网站目录: rm -rf /usr/share/nginx/html/*#清理环境 cp -rwordpress/*/usr/share/nginx/html/ chmod 777 /usr/share/nginx/html/*#授权所有文件 chown -R nginx.nginx /usr/share/nginx/html

拷贝网站目录所有文件给
Nginx服务器:scp -r /usr/share/nginx/html/*192.168.178.7:/usr/share/nginx/html PHP服务器授权: chown -R nginx.nginx/usr/share/nginx/html

注意:两边必须同时有WordPress文件,php的目录是一开始 /etc/nginx/conf.d/default 中
location ~ .php$ {
root /usr/share/nginx/html; #php存放文件的目录
}

浏览器访问页面
http://192.168.178.6#Nginx的IP地址 数据库名:bbs 用户名:phptest 密码:123456 数据库主机:192.168.178.6

LNMP|2021最新LNMP => WordPress分离式部署(实战案例)
文章图片



【LNMP|2021最新LNMP => WordPress分离式部署(实战案例)】

    推荐阅读