虚拟机centos9搭建wordpress

embedded/2024/10/15 22:30:35/

目录

安装环境和搭建简介

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登录


安装环境和搭建简介

centos9虚拟机环境

在centos9利用nginxMariaDB搭建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`:

vim /etc/php-fpm.d/www.conf

user = nginx

group = nginx

listen = 127.0.0.1:9000

可以通过:/user =来进行搜索查找,其他也类似

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 vim wp-config.php

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

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

define( 'DB_NAME', 'wordpress' );

define( 'DB_USER', 'wordpressuser' );

define( 'DB_PASSWORD', 'Huawei@!123' );

define( 'DB_HOST', 'localhost' );

注意:wordpress和Huawei@!123是上面创建的数据库用户和密码,如果你做了修改,换成你对应的用户和密码

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处理过就不会有,如果有权限也会自动创建,无需步骤8

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

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

11.4填写配置信息

11.5登录

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


http://www.ppmy.cn/embedded/94110.html

相关文章

C++之 bind 绑定器深入学习:从入门到精通!

简介 本文详细阐述了 C 中关于 bind 绑定器技术的基本概念和常用技巧。 引入动机 在标准算法库中&#xff0c;有一个算法叫 remove_if&#xff0c;其基本使用如下&#xff1a; #include <iostream> #include <string> #include <algorithm> #include &l…

【ARM】v8架构programmer guide(5)_ARMv8指令集介绍

目录 5.1 ARMv8 指令集 5.1.1 32bit和64bit A64指令的重大区别 5.1.2 地址 5.1.3 寄存器 5.2 不同指令集直接的切换 ARMv8架构中最显著的变化之一是引入了64位指令集。这个指令集补充了现有的32位指令集架构。这一增加使得处理器可以访问64位宽的整数寄存器和数据操作&…

ubuntu将软件放到任务栏

右键点击这个 pycharm 方法1&#xff1a; 方法2&#xff1a; sudo nano /usr/share/applications/PyCharm.desktop 编辑这个 [Desktop Entry] NamePyCharm CommentPyCharm Integrated Development Environment Exec/path/to/PyCharm.sh Icon/path/to/PyCharm.svg Terminalf…

如何使用Jmeter对HTTP接口进行压力测试?

我们不应该仅仅局限于某一种工具&#xff0c;性能测试能使用的工具非常多&#xff0c;选择适合的就是最好的。笔者已经使用Loadrunner进行多年的项目性能测试实战经验&#xff0c;也算略有小成&#xff0c;任何性能测试&#xff08;如压力测试、负载测试、疲劳强度测试等&#…

AJAX基础知识

AJAX&#xff08;Asynchronous JavaScript and XML&#xff09;是一种技术&#xff0c;用于在网页加载时从服务器异步获取数据&#xff0c;而无需重新加载整个页面。它允许在后台与服务器进行通信&#xff0c;提升网页的交互性和用户体验。AJAX 通常结合 JavaScript 和 XML&…

MBTI 性格测试小程序实战

MBTI 性格测试应用介绍 参考项目&#xff1a;16Personalities&#xff08;https://www.16personalities.com/ch&#xff09; MBTI 实现方案介绍 核心组成&#xff1a; 题目用户答案评分规则 题目结构 暂时使用JSON&#xff0c;便于理解&#xff0c;result代表题目对应的…

http跨域网络请求中的CORS(跨源资源共享) 那些事 -- HTTP跨域请求, chrome插件跨域请求使用详解, origin格式,origin通配符等

在我们进行网络应用开发的时候&#xff0c;如果用到了跨域网络请求&#xff0c;则不可避免的就会遇到http跨域网络请求 CORS的问题&#xff0c;今天就和大家来聊聊跨域网络请求中的CORS的那些事。 跨源资源共享&#xff08;CORS&#xff09; CORS 是一种基于 HTTP 头的机制&a…

【Linux】解锁进程地址空间奥秘,高效环境变量的实战技巧

环境变量和进程地址空间 1. 环境变量1.1. 概念1.2. 常见环境变量1.3. 和环境变量相关的命令 2. 命令行参数2.1. int argc、char* argv[]2.2. char* env[] 3. 环境变量的特性4. 环境变量的获取4.1. 代码方式4.2. 系统调用方式 5. 环境变量的配置文件6. 程序地址空间7. 进程地址空…