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

虚拟机centos9搭建wordpress

目录

1. 更换yum源更新系统软件包:

1.1备份yum源

1.1.1创建备份目录:

1.1.2移动现有仓库配置文件到备份目录:

1.1.3验证备份:

1.2更换yum源

1.2.1添加yum源

1.2.2删除和建立yum缓存

1.3更新系统软件包

1.4 yum与dnf介绍

2. 安装 Nginx:

2.1安装

2.2开启服务

3. 安装 MariaDB:

3.1安装

3.2开启服务

4. 安全配置 MariaDB:

5. 创建 WordPress 数据库和用户:

5.1进入数据

5.2创建数据库

5.3创建用户并赋权

6. 安装 PHP:

6.1修改配置文件

6.2启动并启用 PHP-FPM 服务:

7. 下载并配置 WordPress:

8. 配置 WordPress:

8.1复制样本配置文件并编辑:

8.2根据需要更新以下内容:

9. 配置 Nginx:

9.1编辑 Nginx 配置文件

9.2检查 Nginx 配置是否正确:

9.3重新加载 Nginx 配置:

10. 配置 SELinux 和防火墙:

10.1如果启用了 SELinux

10.2配置防火墙允许 HTTP 和 HTTPS 流量:

11. 访问 WordPress 安装界面:

11.1访问

11.2安装

11.3无法写入wp-config.php

11.4填写配置信息

11.5登录

利用nginx和MariaDB搭建wordpress
 

1. 更换yum源更新系统软件包:

1.1备份yum源

1.1.1创建备份目录:

创建一个目录来保存备份的仓库配置文件:

sudo mkdir -p /etc/yum.repos.d/backup

1.1.2移动现有仓库配置文件到备份目录:

将 /etc/yum.repos.d/ 目录中的所有文件移动到备份目录中:

sudo mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/backup/

1.1.3验证备份:

确认备份是否成功,可以列出备份目录中的文件:

ls /etc/yum.repos.d/backup/

1.2更换yum源

可以参考:CentOS Stream - USTC Mirror Help

1.2.1添加yum源

vim /etc/yum.repos.d/centos.repo

[baseos]
name=CentOS Stream $releasever - BaseOS
baseurl=https://mirrors.ustc.edu.cn/centos-stream/$releasever-stream/BaseOS/$basearch/os
# metalink=https://mirrors.centos.org/metalink?repo=centos-baseos-$stream&arch=$basearch&protocol=https,http
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
gpgcheck=1
repo_gpgcheck=0
metadata_expire=6h
countme=1
enabled=1

[baseos-debuginfo]
name=CentOS Stream $releasever - BaseOS - Debug
baseurl=https://mirrors.ustc.edu.cn/centos-stream/$releasever-stream/BaseOS/$basearch/debug/tree/
# metalink=https://mirrors.centos.org/metalink?repo=centos-baseos-debug-$stream&arch=$basearch&protocol=https,http
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
gpgcheck=1
repo_gpgcheck=0
metadata_expire=6h
enabled=0

[baseos-source]
name=CentOS Stream $releasever - BaseOS - Source
baseurl=https://mirrors.ustc.edu.cn/centos-stream/$releasever-stream/BaseOS/source/tree/
# metalink=https://mirrors.centos.org/metalink?repo=centos-baseos-source-$stream&arch=source&protocol=https,http
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
gpgcheck=1
repo_gpgcheck=0
metadata_expire=6h
enabled=0

[appstream]
name=CentOS Stream $releasever - AppStream
baseurl=https://mirrors.ustc.edu.cn/centos-stream/$releasever-stream/AppStream/$basearch/os
# metalink=https://mirrors.centos.org/metalink?repo=centos-appstream-$stream&arch=$basearch&protocol=https,http
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
gpgcheck=1
repo_gpgcheck=0
metadata_expire=6h
countme=1
enabled=1

[appstream-debuginfo]
name=CentOS Stream $releasever - AppStream - Debug
baseurl=https://mirrors.ustc.edu.cn/centos-stream/$releasever-stream/AppStream/$basearch/debug/tree/
# metalink=https://mirrors.centos.org/metalink?repo=centos-appstream-debug-$stream&arch=$basearch&protocol=https,http
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
gpgcheck=1
repo_gpgcheck=0
metadata_expire=6h
enabled=0

[appstream-source]
name=CentOS Stream $releasever - AppStream - Source
baseurl=https://mirrors.ustc.edu.cn/centos-stream/$releasever-stream/AppStream/source/tree/
# metalink=https://mirrors.centos.org/metalink?repo=centos-appstream-source-$stream&arch=source&protocol=https,http
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
gpgcheck=1
repo_gpgcheck=0
metadata_expire=6h
enabled=0

[crb]
name=CentOS Stream $releasever - CRB
baseurl=https://mirrors.ustc.edu.cn/centos-stream/$releasever-stream/CRB/$basearch/os
# metalink=https://mirrors.centos.org/metalink?repo=centos-crb-$stream&arch=$basearch&protocol=https,http
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
gpgcheck=1
repo_gpgcheck=0
metadata_expire=6h
countme=1
enabled=1

[crb-debuginfo]
name=CentOS Stream $releasever - CRB - Debug
baseurl=https://mirrors.ustc.edu.cn/centos-stream/$releasever-stream/CRB/$basearch/debug/tree/
# metalink=https://mirrors.centos.org/metalink?repo=centos-crb-debug-$stream&arch=$basearch&protocol=https,http
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
gpgcheck=1
repo_gpgcheck=0
metadata_expire=6h
enabled=0

[crb-source]
name=CentOS Stream $releasever - CRB - Source
baseurl=https://mirrors.ustc.edu.cn/centos-stream/$releasever-stream/CRB/source/tree/
# metalink=https://mirrors.centos.org/metalink?repo=centos-crb-source-$stream&arch=source&protocol=https,http
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
gpgcheck=1
repo_gpgcheck=0
metadata_expire=6h
enabled=0

vim /etc/yum.repos.d/centos-addons.repo

[highavailability]
name=CentOS Stream $releasever - HighAvailability
baseurl=https://mirrors.ustc.edu.cn/centos-stream/$releasever-stream/HighAvailability/$basearch/os
# metalink=https://mirrors.centos.org/metalink?repo=centos-highavailability-$stream&arch=$basearch&protocol=https,http
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
gpgcheck=1
repo_gpgcheck=0
metadata_expire=6h
countme=1
enabled=0

[highavailability-debuginfo]
name=CentOS Stream $releasever - HighAvailability - Debug
baseurl=https://mirrors.ustc.edu.cn/centos-stream/$releasever-stream/HighAvailability/$basearch/debug/tree/
# metalink=https://mirrors.centos.org/metalink?repo=centos-highavailability-debug-$stream&arch=$basearch&protocol=https,http
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
gpgcheck=1
repo_gpgcheck=0
metadata_expire=6h
enabled=0

[highavailability-source]
name=CentOS Stream $releasever - HighAvailability - Source
baseurl=https://mirrors.ustc.edu.cn/centos-stream/$releasever-stream/HighAvailability/source/tree/
# metalink=https://mirrors.centos.org/metalink?repo=centos-highavailability-source-$stream&arch=source&protocol=https,http
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
gpgcheck=1
repo_gpgcheck=0
metadata_expire=6h
enabled=0

[nfv]
name=CentOS Stream $releasever - NFV
baseurl=https://mirrors.ustc.edu.cn/centos-stream/$releasever-stream/NFV/$basearch/os
# metalink=https://mirrors.centos.org/metalink?repo=centos-nfv-$stream&arch=$basearch&protocol=https,http
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
gpgcheck=1
repo_gpgcheck=0
metadata_expire=6h
countme=1
enabled=0

[nfv-debuginfo]
name=CentOS Stream $releasever - NFV - Debug
baseurl=https://mirrors.ustc.edu.cn/centos-stream/$releasever-stream/NFV/$basearch/debug/tree/
# metalink=https://mirrors.centos.org/metalink?repo=centos-nfv-debug-$stream&arch=$basearch&protocol=https,http
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
gpgcheck=1
repo_gpgcheck=0
metadata_expire=6h
enabled=0

[nfv-source]
name=CentOS Stream $releasever - NFV - Source
baseurl=https://mirrors.ustc.edu.cn/centos-stream/$releasever-stream/NFV/source/tree/
# metalink=https://mirrors.centos.org/metalink?repo=centos-nfv-source-$stream&arch=source&protocol=https,http
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
gpgcheck=1
repo_gpgcheck=0
metadata_expire=6h
enabled=0

[rt]
name=CentOS Stream $releasever - RT
baseurl=https://mirrors.ustc.edu.cn/centos-stream/$releasever-stream/RT/$basearch/os
# metalink=https://mirrors.centos.org/metalink?repo=centos-rt-$stream&arch=$basearch&protocol=https,http
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
gpgcheck=1
repo_gpgcheck=0
metadata_expire=6h
countme=1
enabled=0

[rt-debuginfo]
name=CentOS Stream $releasever - RT - Debug
baseurl=https://mirrors.ustc.edu.cn/centos-stream/$releasever-stream/RT/$basearch/debug/tree/
# metalink=https://mirrors.centos.org/metalink?repo=centos-rt-debug-$stream&arch=$basearch&protocol=https,http
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
gpgcheck=1
repo_gpgcheck=0
metadata_expire=6h
enabled=0

[rt-source]
name=CentOS Stream $releasever - RT - Source
baseurl=https://mirrors.ustc.edu.cn/centos-stream/$releasever-stream/RT/source/tree/
# metalink=https://mirrors.centos.org/metalink?repo=centos-rt-source-$stream&arch=source&protocol=https,http
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
gpgcheck=1
repo_gpgcheck=0
metadata_expire=6h
enabled=0

[resilientstorage]
name=CentOS Stream $releasever - ResilientStorage
baseurl=https://mirrors.ustc.edu.cn/centos-stream/$releasever-stream/ResilientStorage/$basearch/os
# metalink=https://mirrors.centos.org/metalink?repo=centos-resilientstorage-$stream&arch=$basearch&protocol=https,http
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
gpgcheck=1
repo_gpgcheck=0
metadata_expire=6h
countme=1
enabled=0

[resilientstorage-debuginfo]
name=CentOS Stream $releasever - ResilientStorage - Debug
baseurl=https://mirrors.ustc.edu.cn/centos-stream/$releasever-stream/ResilientStorage/$basearch/debug/tree/
# metalink=https://mirrors.centos.org/metalink?repo=centos-resilientstorage-debug-$stream&arch=$basearch&protocol=https,http
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
gpgcheck=1
repo_gpgcheck=0
metadata_expire=6h
enabled=0

[resilientstorage-source]
name=CentOS Stream $releasever - ResilientStorage - Source
baseurl=https://mirrors.ustc.edu.cn/centos-stream/$releasever-stream/ResilientStorage/source/tree/
# metalink=https://mirrors.centos.org/metalink?repo=centos-resilientstorage-source-$stream&arch=source&protocol=https,http
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
gpgcheck=1
repo_gpgcheck=0
metadata_expire=6h
enabled=0

[extras-common]
name=CentOS Stream $releasever - Extras packages
baseurl=https://mirrors.ustc.edu.cn/centos-stream/SIGs/$releasever-stream/extras/$basearch/extras-common
# metalink=https://mirrors.centos.org/metalink?repo=centos-extras-sig-extras-common-$stream&arch=$basearch&protocol=https,http
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-Extras-SHA512
gpgcheck=1
repo_gpgcheck=0
metadata_expire=6h
countme=1
enabled=1

[extras-common-source]
name=CentOS Stream $releasever - Extras packages - Source
baseurl=https://mirrors.ustc.edu.cn/centos-stream/SIGs/$releasever-stream/extras/source/extras-common
# metalink=https://mirrors.centos.org/metalink?repo=centos-extras-sig-extras-common-source-$stream&arch=source&protocol=https,http
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-Extras-SHA512
gpgcheck=1
repo_gpgcheck=0
metadata_expire=6h
enabled=0

1.2.2删除和建立yum缓存

yum clean all

yum makecache

1.3更新系统软件包

sudo dnf update -y

1.4 yum与dnf介绍

CentOS 9 默认使用的是 DNF 作为包管理工具,而不再使用 YUM。虽然 CentOS 9 中没有传统的 YUM 命令,但它提供了一个 yum 的软链接指向 dnf,这意味着你在命令行中输入 yum 实际上是运行 dnf。

以下是一些关键点:

DNF 作为默认包管理工具:CentOS 9 使用 DNF 作为其默认的包管理工具。你可以使用 dnf 命令来安装、更新和删除软件包。

YUM 的兼容性:虽然没有传统的 YUM,但系统提供了一个指向 DNF 的 yum 软链接,这样习惯于使用 yum 的用户仍然可以使用 yum 命令,如同在以前的版本中一样。例如,输入 yum install package 实际上会运行 dnf install package。

命令和功能:在 CentOS 9 中,使用 dnf 命令时,大多数你习惯于在 YUM 中使用的命令和选项仍然适用,因为 DNF 保持了相当的兼容性。

总的来说,在 CentOS 9 上,你可以继续使用 yum 命令,但它实际上是调用 DNF。

2. 安装 Nginx:

2.1安装

sudo yum install nginx -y

2.2开启服务

sudo systemctl start nginx

sudo systemctl enable nginx

3. 安装 MariaDB:

3.1安装

sudo dnf install mariadb-server mariadb -y

3.2开启服务

sudo systemctl start mariadb

sudo systemctl enable mariadb

4. 安全配置 MariaDB:

sudo mysql_secure_installation

按照提示设置 MariaDB root 用户密码并进行其他安全设置。

注意:默认答案都是“yes”(是)

5. 创建 WordPress 数据库和用户:

5.1进入数据

sudo mysql -u root -p

密码

5.2创建数据库

CREATE DATABASE wordpress;

5.3创建用户并赋权

CREATE USER 'wordpressuser'@'localhost' IDENTIFIED BY 'Huawei@!123';

GRANT ALL PRIVILEGES ON wordpress.* TO 'wordpressuser'@'localhost';

FLUSH PRIVILEGES;

EXIT;

6. 安装 PHP:

sudo dnf install php-fpm php-mysqlnd php-json php-xml php-mbstring -y

6.1修改配置文件

编辑 `/etc/php-fpm.d/www.conf` 文件,确保 `user` 和 `group` 设置为 `nginx`:

listen = 127.0.0.1:9000

6.2启动并启用 PHP-FPM 服务:

sudo systemctl start php-fpm

sudo systemctl enable php-fpm

7. 下载并配置 WordPress:

cd /usr/share/nginx/html

sudo curl -O https://wordpress.org/latest.tar.gz

sudo tar -zxvf latest.tar.gz

sudo chown -R nginx:nginx /usr/share/nginx/html

sudo chmod -R 755 /usr/share/nginx/html

8. 配置 WordPress:

(这一步可以跳过的)

8.1复制样本配置文件并编辑:

sudo cp wp-config-sample.php wp-config.php

sudo nano wp-config.php

8.2根据需要更新以下内容:

根据自己的具体内容来做修改:如数据库密码

define( 'DB_NAME', 'wordpress' );

define( 'DB_USER', 'wordpressuser' );

define( 'DB_PASSWORD', 'password' );

define( 'DB_HOST', 'localhost' );

9. 配置 Nginx:

9.1编辑 Nginx 配置文件

vim /etc/nginx/conf.d/wordpress.conf:

server {

    listen 80;

    server_name your_domain_or_IP(更换成你的电脑的ip地址);

    root /usr/share/nginx/html;

    index index.php index.html index.htm;

    location / {

        try_files $uri $uri/ /index.php?$args;

    }

    location ~ \.php$ {

        include /etc/nginx/fastcgi_params;

        fastcgi_pass 127.0.0.1:9000;

        fastcgi_index index.php;

        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

    }

    location ~ /\.ht {

        deny all;

    }

}

9.2检查 Nginx 配置是否正确:

sudo nginx -t

9.3重新加载 Nginx 配置:

sudo systemctl restart nginx

10. 配置 SELinux 和防火墙:

10.1如果启用了 SELinux

运行以下命令:

sudo chcon -t httpd_sys_rw_content_t /usr/share/nginx/html -R

10.2配置防火墙允许 HTTP 和 HTTPS 流量:

sudo firewall-cmd --permanent --add-service=http

sudo firewall-cmd --permanent --add-service=https

sudo firewall-cmd --reload

11. 访问 WordPress 安装界面:

在浏览器中访问您的服务器 IP 地址或域名,例如 `http://your_domain_or_IP`,然后按照屏幕上的说明完成 WordPress 安装。

11.1访问

ifconfig可以查看网络信息

http://ip/wordpress

11.2安装

11.3无法写入wp-config.php

出现这种错误是目录权限问题,如果在步骤8处理过就不会有

vim /etc/share/nginx/html/wordpress/wp-config.php

把上面的东西复制粘贴进去保存

11.4填写配置信息

11.5登录

这样,您就可以在 CentOS 9 上使用 Nginx 成功搭建 WordPress 了。

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • c++ 自定义异常
  • 相机的内参与外参
  • 端到端自动驾驶科普向
  • 数据结构和算法入门
  • 调度器——DolphinScheduler讲解及安装教程
  • 【C++进阶学习】第九弹——哈希的原理与实现——开放寻址法的讲解
  • 测试开发面试题---计算机网络
  • 减轻幻觉新SOTA,7B模型自迭代训练效果超越GPT-4,上海AI lab发布
  • AutoSAR自适应平台架构总览--AP的初认识
  • Python入门第二课
  • 【专题】百度萝卜快跑体验:Robotaxi发展现状与展望报告合集PDF分享(附原数据表)
  • 【CSS】继承属性
  • 【图像标签转换】XML转为TXT图像数据集标签
  • 如何预防网站爬虫攻击
  • SQL39道常见题型
  • 【许晓笛】 EOS 智能合约案例解析(3)
  • Centos6.8 使用rpm安装mysql5.7
  • IOS评论框不贴底(ios12新bug)
  • JavaScript异步流程控制的前世今生
  • Python连接Oracle
  • spring boot下thymeleaf全局静态变量配置
  • 构造函数(constructor)与原型链(prototype)关系
  • 爬虫进阶 -- 神级程序员:让你的爬虫就像人类的用户行为!
  • 七牛云假注销小指南
  • 巧用 TypeScript (一)
  • 让你的分享飞起来——极光推出社会化分享组件
  • 小程序 setData 学问多
  • 用jquery写贪吃蛇
  • 用Python写一份独特的元宵节祝福
  • 用quicker-worker.js轻松跑一个大数据遍历
  • ######## golang各章节终篇索引 ########
  • #NOIP 2014# day.1 T2 联合权值
  • #pragma multi_compile #pragma shader_feature
  • #我与Java虚拟机的故事#连载07:我放弃了对JVM的进一步学习
  • (~_~)
  • (11)MSP430F5529 定时器B
  • (echarts)echarts使用时重新加载数据之前的数据存留在图上的问题
  • (Redis使用系列) Springboot 整合Redisson 实现分布式锁 七
  • (搬运以学习)flask 上下文的实现
  • (二)pulsar安装在独立的docker中,python测试
  • (二十五)admin-boot项目之集成消息队列Rabbitmq
  • (附源码)ssm教材管理系统 毕业设计 011229
  • (附源码)计算机毕业设计ssm本地美食推荐平台
  • (每日持续更新)信息系统项目管理(第四版)(高级项目管理)考试重点整理 第13章 项目资源管理(七)
  • (强烈推荐)移动端音视频从零到上手(上)
  • (三)SvelteKit教程:layout 文件
  • (十八)三元表达式和列表解析
  • (实测可用)(3)Git的使用——RT Thread Stdio添加的软件包,github与gitee冲突造成无法上传文件到gitee
  • (译) 函数式 JS #1:简介
  • .360、.halo勒索病毒的最新威胁:如何恢复您的数据?
  • .java 指数平滑_转载:二次指数平滑法求预测值的Java代码
  • .Mobi域名介绍
  • .Net Core 微服务之Consul(二)-集群搭建
  • .NET Core6.0 MVC+layui+SqlSugar 简单增删改查
  • .Net Core与存储过程(一)