基于nginx部署开源博客平台wordpress;LNMP分布式部署wordpress

基于nginx部署开源博客平台wordpress;LNMP分布式部署wordpress

要求nginx与php分开部署,跨主机通信
环境准备:
ip组件
192.168.10.210nginx version: nginx/1.25.4 wordpress-6.7.1-zh_CN.tar.gz
192.168.10.220PHP74 wordpress-6.7.1-zh_CN.tar.gz
关闭selinux
[root@nginx ~]# sed -i '/^SELINUX=/s/enforcing/disabled/g'  /etc/selinux/config
[root@nginx ~]# setenforce 0
关闭防火墙
[root@nginx ~]# systemctl disable firewalld
[root@nginx ~]# systemctl stop firewalld

Nginx的部署和配置

基础配置
[root@localhost ~]# hostnamectl set-hostname nginx
[root@localhost ~]# bash
[root@nginx ~]# systemctl stop firewalld

[root@nginx ~]# systemctl disable firewalld

[root@nginx ~]# sed -i '/^SELINUX=/s/enforcing/disabled/g'  /etc/selinux/config

[root@nginx ~]# setenforce 0
[root@nginx ~]# getenforce 0
Permissive
安装nginx需要的依赖包和解析软件包
[root@nginx ~]# yum install -y wget net-tools gcc gcc-c++ pcre pcre-devel openssl openssl-devel zlib zlib-devel gd gd-devel
wget在线获取nginx 的压缩包
[root@nginx ~]# wget https://nginx.org/download/nginx-1.24.0.tar.gz

解压nginx ;创建一个名叫nginx的用户

[root@nginx ~]# tar -axf nginx-1.24.0.tar.gz
[root@nginx ~]# useradd -M -s /sbin/nologin nginx

进入到解压出来的nginx包,添加功能模块

[root@nginx ~]# cd nginx-1.24.0
[root@nginx nginx-1.24.0]# ./configure --prefix=/usr/local/nginx --user=nginx  --group=nginx --with-http_stub_status_module  --with-http_ssl_module

编译并安装

[root@nginx nginx-1.24.0]# make && make install

进入到nginx的安装目录,启动nginx

[root@nginx nginx-1.24.0]# cd /usr/local/nginx/
[root@nginx nginx]# ./sbin/nginx

修改nginx 的配置环境,使其中nginx 的命令起作用

[root@nginx nginx]# vim /etc/profile.d/nginx.sh
[root@nginx nginx]# cat /etc/profile.d/nginx.sh
export PATH="/usr/local/nginx/sbin:$PATH"
[root@nginx nginx]# source /etc/profile
[root@nginx nginx]# nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

使用网络工具,查看nginx是否启动成功

[root@nginx nginx]# netstat -tunlp
修改nginx 的主配置文件
[root@nginx nginx]# vim conf/nginx.conf
##########指定其域名
 server {
        listen       80;
        server_name  www.helloone.com;
##############在nginx可读的文件里面,加上.php文件
 location / {
            root   html;
            index index.php index.html index.htm;
        }
##########指定php访问的ip,以及文件
  location ~ \.php$ {
            root           html;
            fastcgi_pass   192.168.10.220:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /php$fastcgi_script_name;
            include        fastcgi_params;
        }

创建一个存放网页文件的文件夹

[root@nginx nginx]# mkdir /php

[root@nginx nginx]#  chown nginx.nginx /php

在修改配置文件后,对nginx进行重载

[root@nginx nginx]# nginx -s reload
[root@nginx nginx]# netstat -tunlp

Mariadb数据库的配置

配置yum源
[root@nginx ~]# cd /etc/yum.repos.d/
[root@nginx yum.repos.d]# vim mariadb.repo

[root@nginx yum.repos.d]# cat mariadb.repo
# MariaDB 10.6 CentOS repository list - created 2023-08-12 01:54 UTC
# https://mariadb.org/download/
[mariadb]
name = MariaDB
# rpm.mariadb.org is a dynamic mirror if your preferred mirror goes offline. See https://mariadb.org/mirrorbits/ for details. # baseurl = https://rpm.mariadb.org/10.6/centos/$releasever/$basearch
baseurl = https://mirrors.aliyun.com/mariadb/yum/10.6/centos/$releasever/$basearch
module_hotfixes = 1
# gpgkey = https://rpm.mariadb.org/RPM-GPG-KEY-MariaDB
gpgkey = https://mirrors.aliyun.com/mariadb/yum/RPM-GPG-KEY-MariaDB
gpgcheck = 1

[root@nginx yum.repos.d]# yum clean all   ##清理缓存
[root@nginx yum.repos.d]# yum makecache   ##建立新的元缓存
安装mariadb
[root@nginx ~]# yum install -y  MariaDB-server MariaDB-client
[root@nginx ~]# systemctl start mariadb
[root@nginx ~]# mysql


MariaDB [(none)]> create database wordpress;
##创建wordpress用户,并指定是访问ip,设定密码
MariaDB [(none)]> create user 'wordpress'@'192.168.10.210(%)' identified by '000000'; 
##授权让wordpress用户使用其数据库
MariaDB [(none)]> grant all privileges on wordpress.* to 'wordpress'@'192.168.10.210(%)';
MariaDB [(none)]> flush privileges;   ## 刷新

PHP的安装配置

在192.168.10.220上操作
修改主机名;然后使用wget获取remi-release 依赖
[root@localhost ~]# hostnamectl set-hostname php
[root@localhost ~]# bash

[root@php ~]# yum install -y  wget net-tools 
[root@php ~]# wget https://mirrors.aliyun.com/remi/enterprise/remi-release-7.rpm
[root@php ~]# yum -y install remi-release-7.rpm
[root@php ~]# yum -y install  php80 php80-php php80-php-xml php80-php-xmlrpc php80-php-pecl-mcrypt php80-php-fpm php80-php-pecl-apcu php80-php-mbstring php80-php-gd php80-php-json php80-php-pecl-json-post php80-php-pdo php80-php-mysqlnd php80-php-pecl-mysql php80-php-opcache php80-php-pear php80-php-soap php80-php-intl php80-php-pear php-pear-MDB2-Driver-mysqli.noarch
[root@php ~]# cd /etc/opt/remi/php74/php-fpm.d/
[root@php php-fpm.d]# vim www.conf         ###修改配置文件
###把 = apache改为 = nginx
user = nginx
###把 = apache改为 = nginx
group = nginx
###把listen = 127.0.0.1.9000修改为
listen = 0.0.0.0:9000
###把127.0.0.1修改为nginx 的主机ip地址
listen.allowed_clients = 192.168.10.210

#创建用户和nginx服务器的用户要一致
[root@php php-fpm.d]# useradd -M -s /sbin/nologin nginx
#启动php
[root@php php-fpm.d]# systemctl start php80-php-fpm.service
[root@php php-fpm.d]# systemctl enable php80-php-fpm.service
#查看php-fpm 的端口起来没有
[root@php ~]# netstat -tunlp

#####################
#####或者#### #####另外一种安装php的方式
[root@php ~]# yum install epel-release wget net-tools -y
[root@php ~]# rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
[root@php ~]# yum --enablerepo=remi install php74-php php74-php-devel php74-php-fpm php74-php-gd php74-php-xml  php74-php-sockets php74-php-session php74-php-snmp php74-php-mysql -y
###修改配置文件
[root@php ~]# cd /etc/opt/remi/php74/php-fpm.d/
[root@php php-fpm.d]# vim www.conf         ###修改配置文件
###把 = apache改为 = nginx
user = nginx
###把 = apache改为 = nginx
group = nginx
###把listen = 127.0.0.1.9000修改为
listen = 0.0.0.0:9000
###把127.0.0.1修改为nginx 的主机ip地址
listen.allowed_clients = 192.168.10.210

#创建用户和nginx服务器的用户要一致
[root@php php-fpm.d]# useradd -M -s /sbin/nologin nginx
###开启php
[root@php ~]# /opt/remi/php74/root/usr/sbin/php-fpm   
#查看php-fpm 的端口起来没有
[root@php ~]# netstat -tunlp
###                             #####okay####
测试php

在php的服务器上编写php的测试页面

[root@php ~]# cat > /php/t1.php << EOF
<?php
phpinfo()
?>
EOF
在windows上做本地域名解析

在这里插入图片描述

然后在网页进行测试

在这里插入图片描述

Wordpress 的部署和配置

把下载好的wordoress 资源包分别上传到nginx和php服务器;分别进行解压和修改配置文件
[root@php ~]# tar -axf wordpress-6.7.1-zh_CN.tar.gz
[root@php ~]# cd wordpress
##把默认的主配置文件进行备份;并且修改主要的文件内容;然后把全部文件移动到指定的目录下
[root@php wordpress]# cp wp-config-sample.php wp-config.php
[root@php wordpress]# vim wp-config.php
[root@php ~]# mv ./* /php

define( 'DB_NAME', 'wordpress' );    

/** Database username */
define( 'DB_USER', 'wordpress' );

/** Database password */
define( 'DB_PASSWORD', '000000' );

/** Database hostname */
define( 'DB_HOST', '192.168.10.210' );
修改配置文件后,对nginx和php都进行重载pwd
[root@nginx wordpress]# scp wp-config.php 192.168.10.220:/php

[root@nginx wordpress]# mv ./* /usr/local/nginx/html/

# nginx -s reload 

# systemctl restart php80-php-fpm

最后再根据自己的ip地址 在浏览器上访问就可以了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值