首页 > 系统相关 >虚拟机centos9搭建wordpress

虚拟机centos9搭建wordpress

时间:2024-07-20 20:57:12浏览次数:24  
标签:stream centos mirrors 虚拟机 repo wordpress https releasever centos9

利用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 了。

标签:stream,centos,mirrors,虚拟机,repo,wordpress,https,releasever,centos9
From: https://blog.csdn.net/FHYAALML/article/details/140576161

相关文章

  • Javascript 在我的本地服务器上运行,但在 WordPress 上不起作用
    大家好,我有一个问题。我有一个在本地服务器中完美运行的模板/主题,但是当我将其移动到Wordpress时,根据我的研究,我得到了“jQuery不兼容”的信息。 我附上了代码的图像。你能帮我一下吗,一切看起来都很完美,在我看来一切都很完美,但在Wordpress中却不然。提前谢谢你!......
  • 一种优秀的虚拟机内存架构 - AQ
    源链接:https://www.axa6.com/zh/an-excellent-virtual-machine-memory-architecture简介虚拟机内存架构直接影响虚拟机的性能和占用。设计一个优秀的架构可以有效提升性能和效率。本文将介绍AQ虚拟机使用的内存架构,以及AQ虚拟机内存的详细标准。通过对于虚拟机内存架构的优化,......
  • Docker部署wordpress-6.6
    目录一.环境准备二.准备对应的配置文件三.编写Dockerfile四.构建镜像五.配置MySQL 六.安装wordpress 七.扩展一.环境准备localhost192.168.226.25rocky_linux9.4Dockerversion27.0.3关闭防火墙和selinux,进行时间同步。安装docker#step1:安装必......
  • [深入理解Java虚拟机]Hotspot垃圾回收算法
    HotSpot的算法细节实现3.2、3.3节从理论原理上介绍了常见的对象存活判定算法和垃圾收集算法,Java虚拟机实现这些算法时,必须对算法的执行效率有严格的考量,才能保证虚拟机高效运行。本章设置这部分内容主要是为了稍后介绍各款垃圾收集器时做前置知识铺垫,如果读者对这部分内容感到枯......
  • 记一次VMware 虚拟机遇到意外重启的内核级排查操作
    背景:用户业务虚拟机遇到不明原因导致操作系统重启,引起业务中断需求:要求排查具体原因,定位问题根源先来查看虚拟机的事件,事件发生时间:13:37:21 再到虚拟机对应的宿主机查看相关日志,宿主机日志看到的时间需+8才能与VCenter上的事件时间对应得上,因此我们过滤05:37分左右的日志......
  • WordPress 下纯代码实现文章发布、更新后自动清理 CloudFlare 缓存
    最近明月一个参考【WordPress、Typecho站点如何让 CloudFlare 缓存加速】一文开启WordPress站点CloudFlare缓存的客户提出一个疑问,为啥新发布了文章或者修改了文章后网站首页会不能事实的同步更新?这个其实是因为客户在设置CloudFlare缓存时候边缘TTL缓存时间过长以及浏......
  • CentOS9中MySQL8数据库备份--增量备份方案
    1.关于备份:MySQL中有完全备份、增量备份和差异备份三种常见的备份策略,这次使用增量备份定义:增量备份仅备份自上一次备份(无论是完全备份还是增量备份)以来发生变化的数据。特点:依赖于上一次备份,仅备份变化的部分,因此备份文件较小,但恢复时需要结合之前的备份。优点:备份文件......
  • wordpress随机显示指定分类下内容的tag标签
    要在WordPress中随机显示指定分类下的内容标签,你可以使用以下方法:首先,在你的主题文件夹中找到functions.php文件。如果没有这个文件,你可以创建一个新的functions.php文件并将其上传到主题文件夹。在functions.php文件中,添加以下代码:functionget_random_tags_from_specific_c......
  • 杭州外贸网站建设 最好用wordpress模板来搭建
    防护服wordpress外贸网站模板消防服、防尘服、隔热服、防化服、防静电服、电焊服wordpress外贸网站模板。https://www.jianzhanpress.com/?p=4116工业品wordpress外贸网站模板机械及行业设备、五金工具、安全防护、包装、钢铁、纺织皮革等工业品wordpress外贸网......
  • 虚拟机网络配置最佳实践
    一、虚拟网卡配置1.1设置虚拟网卡点击VMwareNetworkAdapterVMnet8设置虚拟网卡注意要点:1.设置静态IP,地址为:192.168.2.1002.设置子网掩码(默认):255.255.255.03.设置默认网关:192.168.2.1(重要!!!这里要跟下面虚拟机网络设置中的NAT设置中的网关IP一致)2.3DHCP设置......