基于nginx部署开源博客平台wordpress;LNMP分布式部署wordpress
要求nginx与php分开部署,跨主机通信
环境准备:
ip | 组件 |
---|---|
192.168.10.210 | nginx version: nginx/1.25.4 wordpress-6.7.1-zh_CN.tar.gz |
192.168.10.220 | PHP74 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地址 在浏览器上访问就可以了