时迁886头像
LNMP架构之WordPress部署封面图

LNMP架构之WordPress部署

一、项目简介

本项目围绕LNMP架构(Linux + Nginx + MySQL + PHP)展开,以WordPress博客系统的部署为核心实践内容,面向云计算应用比赛场景,综合考察选手在Linux系统管理、Web服务配置、数据库管理、PHP环境搭建以及应用部署运维等方面的综合能力。

二、项目背景

随着云计算技术的快速发展,企业上云已成为数字化转型的必然趋势。LNMP作为经典的Web服务架构组合,凭借其高性能、高稳定性和开源免费的优势,被广泛应用于各类Web应用的部署与运维。WordPress作为全球使用最广泛的内容管理系统之一,其部署过程涵盖了LNMP架构中各个核心组件的配置与协同工作,是检验云计算应用能力的典型实践项目。

三、项目目标

  • 掌握Linux操作系统的基础管理与服务配置方法。
  • 熟练完成Nginx Web服务器的安装、配置与优化。
  • 掌握MySQL数据库的安装、建库、授权及日常管理。
  • 完成PHP环境的搭建以及与Nginx、MySQL的协同配置。
  • 实现WordPress的完整部署、初始化配置与访问验证。
  • 具备基本的故障排查与性能优化能力。

四、操作步骤
 

1.基础环境配置

配置主机名
[root@localhost ~]# hostnamectl set-hostname lnmp

重启
下载并解压软件

[root@lnmp ~]# curl -O http://mirrors.zcloudedu.com/cloud/wp-lnmp-c7.9.tar.gz
[root@lnmp ~]# tar -zxvf wp-lnmp-c7.9.tar.gz -C /opt/
[root@lnmp ~]# ls /opt/wp-lnmp-c7.9/
wordpress-4.7.3-zh_CN.zip  wordpress-4.7.3.zip  yum-repo

YUM配置
[root@lnmp ~]# mv /etc/yum.repos.d/* /media/
[root@lnmp ~]# cat >> /etc/yum.repos.d/local.repo << EOF
[lnmp]
baseurl=file:///opt/wp-lnmp-c7.9/yum-repo/
gpgcheck=0
enabled=1
name=lnmp
EOF

关闭selinux
[root@lnmp ~]# setenforce 0
[root@lnmp ~]# sed -i 's/SELINUX=.*/SELINUX=disabled/' /etc/selinux/config

2.部署MYSQL服务

安装MySQL数据库
[root@lnmp ~]# yum install mariadb-server -y

实例化数据库
实例化数据库为数据库创建登录密码,由于默认安装完MySQL数据库,服务并未启动,因此需要先进行启动数据库:

[root@lnmp ~]# systemctl enable mariadb --now
[root@lnmp ~]# mysqladmin -uroot password 'lnmp@zcloud'

3.部署Nginx服务

安装nginx服务
[root@lnmp ~]# yum install nginx -y

启动Nginx服务
[root@lnmp ~]# systemctl enable nginx --now


4.部署PHP服务

安装PHP服务

Nginx服务默认不支持PHP文件,需要安装php-fpm服务与php相关拓展包:

[root@lnmp ~]# yum install php-fpm -y php-*
[root@lnmp ~]# systemctl enable --now php-fpm


配置LNMP环境
配置php-fpm
[root@lnmp ~]# vi /etc/php-fpm.d/www.conf
39 user = nginx
40 ; RPM: Keep a group allowed to write in log dir.
41 group = nginx

注:vi /etc/php-fpm.d/www.conf是进入编辑模式
i是进入编辑
esc退出
shift+: 输入:wq 保存

配置MySQL支持中文:
[root@lnmp ~]# vi /etc/my.cnf
[mysqld]
character-set-server=utf8

重新启动服务
[root@lnmp ~]# systemctl restart mariadb php-fpm

5.部署WordPress

解压WordPress压缩包
[root@lnmp ~]# yum install -y unzip
[root@lnmp ~]# cd /opt/wp-lnmp-c7.9
[root@lnmp wp-lnmp-c7.9]# unzip wordpress-4.7.3-zh_CN.zip

这里我输入unzip wordpress-4.7.3-zh_CN.zip 响应太快了作者没有反应过来

拷贝文件
[root@lnmp wp-lnmp-c7.9]# rm -rf /usr/share/nginx/html/*
[root@lnmp wp-lnmp-c7.9]# cp -r wordpress/* /usr/share/nginx/html/
[root@lnmp wp-lnmp-c7.9]# chown nginx:nginx -R /usr/share/nginx/html
[root@lnmp wp-lnmp-c7.9]# chmod 777 -R /usr/share/nginx/html/*
配置Nginx环境

修改Nginx配置文件,添加新端口号和访问目录,实现WordPress环境访问(添加的部分内容如下截图所示)。
 

[root@lnmp ~]# vi /etc/nginx/nginx.conf
user root;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
include /usr/share/nginx/modules/*.conf;
events {
    worker_connections 1024;
}
http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;
    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;
    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;
    include /etc/nginx/conf.d/*.conf;
    server {
        listen       80 default_server;
        listen       [::]:80 default_server;
        server_name  _;
        root         /usr/share/nginx/html;
        index index.php index.html;              # 注意修改
        include /etc/nginx/default.d/*.conf;
        location ~ \.php$ {
                root           html;
                fastcgi_pass   127.0.0.1:9000;
                fastcgi_index  index.php;
                fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html/$fastcgi_script_name;
                include        fastcgi_params;

        }
        error_page 404 /404.html;
        location = /404.html {
        }
        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
        }
    }
 [root@lnmp ~]# systemctl restart nginx
 [root@lnmp ~]# systemctl restart php-fpm


进入编辑模式输入/root 回车
在我框选的位置进行修改后保存



创建数据库并设置访问权限
[root@lnmp ~]# mysql -uroot -plnmp@zcloud
MariaDB [(none)]> create database wordpress charset utf8;
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> grant all privileges on *.* to root@localhost identified by 'lnmp@zcloud' with grant option;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> grant all privileges on *.* to root@"%" identified by 'lnmp@zcloud' with grant option;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> exit;
Bye

初始化
使用图形化机器访问lnmp节点:
配置数据库连接

配置站点
输入相关信息配置站点。
登陆站点
输入<站点IP>/wp-admin访问管理员登陆页面:

我们这里是10.200.101.196/wp-admin

登录后出现仪表盘就完成了

转载自 CSDN-专业IT技术社区

原文链接:https://blog.csdn.net/2302_80018806/article/details/168121647

文章来源转载

评论

评论列表

微信小程序
QQ小程序

关于作者

点赞数:0
关注数:0
粉丝:0
文章:0
关注标签:0
加入于:--