当前位置: 首页 > news >正文

基于openEuler系统部署WordPress个人博客网站

案例分析基于openEuler系统部署WordPress个人博客网站

1. 规划节点

节点规划,见表1。

表1 节点规划

IP 主机名 节点
192.168.100.3 wordpress nginx、php、mysql、wordpress

2. LNMP简介

LNMP 是由 Linux 操作系统Nginx Web 服务器MySQL 数据库PHP 脚本语言 组成的 高性能动态网站部署方案,广泛应用于现代 Web 开发领域。它通过各组件的协同工作,实现了对静态资源、动态逻辑和数据存储的高效管理,是部署 WordPress、电商系统、API 服务等动态网站的核心技术栈之一。LNMP 以开源免费轻量灵活高并发支持 为核心优势,解决了传统 LAMP(Apache + MySQL + PHP)架构在性能和可扩展性上的局限,成为云原生时代动态网站开发的标准解决方案。

  1. Linux 操作系统
    • 提供稳定运行环境,管理硬件资源和系统服务。
    • 支持主流发行版(如 Ubuntu、CentOS),适配性强。
  2. Nginx Web 服务器
    • 高性能反向代理与负载均衡,优化静态资源(HTML/CSS/JS/图片)的响应速度。
    • 通过 FastCGI 协议与 PHP-FPM 协作,高效处理动态请求。
  3. MySQL 数据库
    • 支持结构化数据存储,提供事务处理与 ACID 特性,保障数据一致性。
    • 适配 PHP 的 mysqli/PDO 扩展,实现灵活的数据交互。
  4. PHP 动态脚本语言
    • 解析 .php 文件,生成动态 HTML 内容,执行业务逻辑(如用户认证、表单处理)。
    • 与 MySQL 协同工作,构建动态网站的核心功能。

3. LNMP 工作原理与协作流程

当用户通过浏览器访问网站时,请求将按以下标准化流程高效流转:

(1) Nginx 接收请求

  • 用户输入 URL(如 http://example.com/index.php

  • Nginx 根据 nginx.conf

    配置智能判断请求类型:

    • 静态资源.html, .css, .js, .jpg):直接返回文件
    • 动态资源.php):转发至 PHP 处理器(PHP-FPM)

(2) PHP-FPM 解析动态请求

  • Nginx 通过 FastCGI 协议.php 请求精准转发至 PHP-FPM
  • PHP-FPM 启动子进程执行 PHP 脚本,完成以下关键步骤:
    • 加载 PHP 代码(如 WordPress 的 wp-blog-header.php
    • 连接 MySQL 数据库,执行 SQL 查询(如获取文章列表)
    • 将查询结果嵌入 HTML 模板,生成最终页面

(3)MySQL 提供数据支持

  • PHP 脚本通过 wp-config.php 中的数据库参数连接 MySQL:
    • DB_NAME:数据库名
    • DB_USER:数据库用户名
    • DB_PASSWORD:数据库密码
  • 执行 SQL 语句(如 SELECT * FROM wp_posts
  • 将查询结果安全返回给 PHP 用于动态内容生成

(4)Nginx 返回响应

  • PHP-FPM 将生成的 HTML 完整返回给 Nginx
  • Nginx 通过 HTTP 协议将响应高效传输至用户浏览器
  • 全流程完成:用户浏览器渲染最终页面

关键特性
该流程通过 Nginx 静态资源直连 + FastCGI 动态请求转发 实现最优性能,避免 Apache 的进程模型开销,单服务器可支撑 10,000+ 并发连接(实测数据)。

4. 基础准备

修改主机名

[root@localhost ~]# hostnamectl set-hostname wordpress
[root@localhost ~]# bashWelcome to 6.6.0-28.0.0.34.oe2403.x86_64System information as of time:  Wed Dec  3 09:05:12 PM CST 2025System load:  0.01
Memory used:  4.4%
Swap used:  0%
Usage On:   3%
IP address:   192.168.100.4
Users online:   1[root@wordpress ~]# 

设置防火墙和selinux开机不自启

[root@wordpress ~]# systemctl disable firewalld --now && setenforce 0

永久关闭selinux

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

配置华为云YUM源,openEuler常用repo源链接

[root@wordpress ~]# cp -rvf /etc/yum.repos.d/openEuler.repo /tmp/
[root@wordpress ~]# sed -i \-e '/^baseurl/ s#http://repo.openeuler.org#https://mirrors.huaweicloud.com/openeuler#g' \-e '/^gpgkey/ s#http://repo.openeuler.org#https://mirrors.huaweicloud.com/openeuler#g' \/etc/yum.repos.d/openEuler.repo

清理YUM/DNF的所有缓存文件(包括元数据、软件包缓存等)并快速生成YUM缓存

[root@wordpress ~]# yum clean all
[root@wordpress ~]# yum makecache

安装工具

[root@wordpress ~]# yum install -y vim tar net-tools lrzsz lsof bash-com*
[root@wordpress ~]# source /etc/profile

案例实施

1. 部署 Nginx 环境

(1)安装nginx
[root@wordpress ~]# yum install -y nginx
(2)启动nginx
[root@wordpress ~]# systemctl enable nginx --now

浏览器测试访问nginx首页

image-20251203212620547

2. 部署 MySQL 环境

(1)安装mysql
[root@wordpress ~]# yum install -y mysql-server
(2)设置mysql开机自启
[root@wordpress ~]# systemctl enable mysqld --now
(3)创建wordpress数据库

设置mysql的root密码

[root@wordpress ~]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.44 Source distributionCopyright (c) 2000, 2025, Oracle and/or its affiliates.Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> alter user 'root'@'localhost' identified by '000000';
Query OK, 0 rows affected (0.03 sec)mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

直接登录失败需要使用密码登录

[root@wordpress ~]# mysql -uroot -p000000
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.0.44 Source distributionCopyright (c) 2000, 2025, Oracle and/or its affiliates.Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql>

创建wordpress用户和wordpress数据库

mysql> create database wordpress;
Query OK, 1 row affected (0.00 sec)mysql> create user 'wordpress'@'localhost' identified by '123456';
Query OK, 0 rows affected (0.02 sec)mysql> grant all privileges on wordpress.* to 'wordpress'@'localhost';
Query OK, 0 rows affected (0.01 sec)mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)mysql> show grants for 'wordpress'@'localhost';
+------------------------------------------------------------------+
| Grants for wordpress@localhost                                   |
+------------------------------------------------------------------+
| GRANT USAGE ON *.* TO `wordpress`@`localhost`                    |
| GRANT ALL PRIVILEGES ON `wordpress`.* TO `wordpress`@`localhost` |
+------------------------------------------------------------------+
2 rows in set (0.00 sec)

3. 部署 PHP 环境

(1)安装php
[root@wordpress ~]# yum install -y php php-fpm php-mysqlnd php-gd php-common php-cli php-mbstring php-xml php-opcache
# PHP核心解释器:解析执行PHP代码,PHP运行的基础
# PHP-FPM进程管理器:接收Nginx请求并管理PHP进程,实现PHP与Nginx协同
# MySQL原生驱动:高效连接MySQL/MariaDB数据库,支持数据操作
# GD图形扩展:处理图片生成、裁剪等,满足图片功能需求
# PHP通用组件库:提供基础配置和公共函数,支撑其他扩展
# PHP命令行工具:终端执行PHP脚本,用于调试和命令行操作
# 多字节字符串扩展:处理中文等多字节字符,解决编码问题
# XML解析扩展:支持XML数据处理,适配依赖XML的功能
# Opcode缓存扩展:缓存预编译代码,提升PHP运行性能
(2)设置php开机自启
[root@wordpress ~]# systemctl enable php-fpm --now

4. 配置 Nginx 解析 PHP

(1)配置 nginx 文件
[root@wordpress ~]# vim /etc/nginx/conf.d/wordpress.conf
# WordPress站点专属配置(适配LNMP架构,基于Unix Socket连接PHP-FPM)
server {# 监听80端口(HTTP默认端口),接收所有网卡的HTTP请求listen 80;# 设置网站根目录:Nginx查找网页文件的基础路径root /usr/share/nginx/html;# 设置服务器匹配域名:本地测试用localhost,生产环境可改为实际域名server_name localhost;# 字符集配置(如需启用可去掉#,指定网页字符编码)#charset koi8-r;# 访问日志路径(如需记录站点访问日志可去掉#)#access_log /var/log/nginx/log/wordpress.access.log main;# ========== 超时与上传优化配置 ==========# 允许客户端最大上传文件大小(解决WordPress上传主题/插件过大问题)client_max_body_size 64M;# FastCGI读取超时时间(延长PHP脚本执行时长,适配长任务)fastcgi_read_timeout 300;# FastCGI发送超时时间(Nginx向PHP-FPM传输请求的超时阈值)fastcgi_send_timeout 300;# 客户端请求体读取超时时间(防止慢速客户端占用连接)client_body_timeout 300;# 客户端请求头读取超时时间(提升连接复用效率)client_header_timeout 300;# ========== 根路径请求处理 ==========location / {# 定义默认首页优先级:优先执行PHP脚本,再加载静态页面index index.php index.html index.htm;# 支持WordPress固定链接(伪静态),若无需求可注释try_files $uri $uri/ /index.php?$args;}# ========== 错误页面配置 ==========# 自定义404页面(如需启用可去掉#,并创建对应文件)#error_page 404 /404.html;# 配置5xx服务器错误跳转页面error_page 500 502 503 504 /50x.html;# 精确匹配50x错误页面请求location = /50x.html {# 错误页面文件所在目录(与网站根目录一致)root /usr/share/nginx/html;}# ========== PHP脚本解析配置 ==========# 正则匹配所有.php结尾的请求(~区分大小写,适配PHP文件)location ~ .php$ {# 转发到PHP-FPM的Unix Socket(通过upstream php-fpm定义)fastcgi_pass php-fpm;# 设置PHP默认索引文件fastcgi_index index.php;# 传递PHP脚本真实路径给PHP-FPM(核心参数,避免文件找不到)fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;# 引入FastCGI通用参数(包含请求方法、HTTP头信息等)include fastcgi_params;}# ========== 静态资源优化(可选) ==========# 对图片、CSS、JS等静态文件设置缓存,减轻服务器压力location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ {expires 30d;  # 缓存有效期30天add_header Cache-Control "public, max-age=2592000";}
}
(2)重新加载 nginx 配置

检查nginx配置文件语法是否正确(包含主配置及所有子配置文件),提前发现语法错误避免服务异常

[root@wordpress ~]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

nginx配置热加载(平滑重载):不中断现有服务的情况下,使新配置生效(旧连接不中断,新请求用新配置)

[root@wordpress ~]# nginx -s reload
(3)测试 nginx 解析 php
[root@wordpress ~]# vim /usr/share/nginx/html/info.php
<?php
/*** 测试PHP解析是否正常* 访问方式:http://你的服务器IP/info.php*/
phpinfo();  // 输出PHP环境配置、模块信息等,确认PHP解析生效
?>

浏览器访问:http://你的服务器IP/info.php

image-20251203221242874

(4)测试 mysql 数据库连接
[root@wordpress ~]# vim /usr/share/nginx/html/mysql_connection.php
<?php
/*** MySQL连接测试* 访问方式:http://你的服务器IP/mysql_connection.php*/
$db_host = 'localhost';
$db_user = 'wordpress';
$db_pass = '123456';
$db_name = 'wordpress';$conn = mysqli_connect($db_host, $db_user, $db_pass, $db_name);if (!$conn) {$status = "❌ 连接失败";$message = "错误: " . mysqli_connect_error();
} else {$status = "✅ 连接成功";$message = "数据库: <strong>{$db_name}</strong><br>版本: " . mysqli_get_server_info($conn);mysqli_close($conn);
}
?><!DOCTYPE html>
<html lang="zh-CN">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>MySQL连接测试结果</title><style>* { margin: 0; padding: 0; box-sizing: border-box; }body {font-family: 'Segoe UI', 'PingFang SC', sans-serif;background: linear-gradient(135deg, #1e3a8a 0%, #0c4a6e 100%);min-height: 100vh;display: flex;justify-content: center;align-items: center;color: white;text-align: center;padding: 20px;}.container {background: rgba(0, 0, 0, 0.6);border-radius: 25px;padding: 45px 55px;max-width: 90%;box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);backdrop-filter: blur(10px);border: 1px solid rgba(255, 255, 255, 0.1);}.status {font-size: 48px;margin-bottom: 25px;text-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);animation: pulse 2s infinite;}.message {font-size: 22px;line-height: 1.6;margin-bottom: 35px;font-weight: 500;color: #e0f2fe;}.version {font-size: 18px;color: #a5b4fc;margin-top: 20px;font-style: italic;}.note {margin-top: 40px;font-size: 15px;color: #cbd5e0;font-style: italic;border-top: 1px dashed rgba(255, 255, 255, 0.2);padding-top: 20px;}@keyframes pulse {0% { box-shadow: 0 0 0 0 rgba(255, 255, 255, 0.4); }70% { box-shadow: 0 0 0 15px rgba(255, 255, 255, 0); }100% { box-shadow: 0 0 0 0 rgba(255, 255, 255, 0); }}</style>
</head>
<body><div class="container"><div class="status"><?= $status ?></div><div class="message"><?= $message ?></div><div class="version">—— 由MySQL连接测试工具生成</div><div class="note">💡 提示:测试完成后请立即删除此文件!生产环境切勿暴露密码</div></div>
</body>
</html>

浏览器访问:http://你的服务器IP/mysql_connection.php

image-20251203223350591

5. 部署 WordPress 至 Nginx 根目录

(1)下载源代码并解压
[root@wordpress ~]# wget https://cn.wordpress.org/wordpress-latest-zh_CN.zip
[root@wordpress ~]# unzip wordpress-latest-zh_CN.zip
(2)配置 wordpress

复制源码至nginx

[root@wordpress ~]# cp -rvf wordpress/* /usr/share/nginx/html/

将 WordPress 默认提供的配置示例文件复制并重命名为 WordPress 运行必需的正式配置文件

[root@wordpress ~]# cp /usr/share/nginx/html/wp-config-sample.php /usr/share/nginx/html/wp-config.php

编辑正式配置文件

[root@wordpress ~]# vim /usr/share/nginx/html/wp-config.php
...
// ** MySQL 设置 - 具体信息来自您的主机服务提供商 ** //
/** WordPress数据库的名称 */
define( 'DB_NAME', 'wordpress' ); // 填写之前创建的数据库名/** MySQL数据库用户名 */
define( 'DB_USER', 'wordpress' ); // 填写数据库用户名/** MySQL数据库密码 */
define( 'DB_PASSWORD', '你的数据库密码' ); // 填写用户对应的密码/** MySQL主机 */
define( 'DB_HOST', 'localhost' ); // 数据库主机(本地填localhost即可)/** 创建数据表时默认的文字编码 */
define( 'DB_CHARSET', 'utf8mb4' );/** 数据库整理类型。如不确定请勿更改 */
define( 'DB_COLLATE', '' );
...

设置权限

[root@wordpress ~]# chmod -R 777 /usr/share/nginx/html/
(3)浏览器安装 wordpress

image-20251203224929981

(4)登录 wordpress

用户名/密码:admin/000000

image-20251203225011179

(5)美化网站

使用提供的WordPress项目包和数据库文件上传到服务器并替换源文件

[root@wordpress ~]# tar -zxvf wordpress-dist.tar.gz
[root@wordpress ~]# cp -rvf dist/* /usr/share/nginx/html/
[root@wordpress ~]# chmod -R 777 /usr/share/nginx/html/

导入数据库文件

[root@wordpress ~]# mysql -uroot -p wordpress < dist/wordpress.sql

浏览器访问

image-20251203232937072

http://www.jsqmd.com/news/701133/

相关文章:

  • 自动化任务系列之二:批量建目录树——Excel模板驱动千人项目初始化
  • 365 Data Science免费开放:数据科学与AI学习全攻略
  • Claude HUD:AI编程副驾驶的实时状态仪表盘插件
  • AIGNE DocSmith:基于AI Agent的自动化文档生成系统实战指南
  • 分布式量子计算:架构演进与关键技术解析
  • 西门子 S7-300 PLC 多触摸屏以太网通讯工程应用
  • AI驱动开发工具全景解析:从GitHub Copilot到工作流重构
  • ARM CP15协处理器:内存管理与缓存控制详解
  • 自编码器特征提取技术解析与实践应用
  • VSCode插件加密能力突变!2026版新增JIT字节码混淆+GPU加速AES-GCM,券商DevOps团队已强制启用
  • 德国信贷数据集不平衡分类问题解析与解决方案
  • LoRA技术在Stable Diffusion中的高效微调与应用实践
  • 2026 网络安全大变局:六大趋势,企业再不布局就晚了
  • 滴滴KnowAgent日志采集平台:从可观测性到大规模集群治理实战
  • MLP、CNN与RNN选型指南:深度学习三大经典网络解析
  • 终身学习型LLM智能体:克服灾难性遗忘,构建持续进化的AI系统
  • 基于强化学习的浏览器自动化智能体:HyperAgent 架构与实战
  • VSCode 2026代码生成插件部署失败率高达63%?——基于17,842个企业环境的日志分析报告
  • JavaScript中利用宏任务拆分阻塞任务的实操案例
  • HTTP Content-Type介绍(x-www-form-urlencoded、multipart/form-data、text/plain、text/html、octet-stream)内容类型
  • LightGlue深度解析:从自适应剪枝到高速特征匹配的实战指南
  • 地标识别:机器学习入门实战指南
  • AI短视频引擎:从文本到视频的自动化内容生成技术解析
  • Reqwest 兼顾简洁与高性能的现代 HTTP 客户端
  • 碧蓝航线自动化脚本终极指南:解放双手的全能助手
  • 《100个“反常识”经验11:删了30万行数据表还是那么大?》
  • 5分钟终极指南:一键解密网易云NCM音乐文件,免费高效转换音频格式
  • 【GPU程序员紧急预警】CUDA 13默认启用PTX JIT缓存机制,导致A100集群批量core dump?3步定位+2行代码修复方案
  • 【计算机毕业设计】基于Springboot的城镇保障性住房管理系统+LW
  • ARM CP15协处理器详解:寄存器配置与系统控制