在 CentOS 上部署 WordPress 时,通常并不需要特定版本的 CentOS 才能运行 WordPress,但为了稳定性、安全性以及兼容性考虑,推荐使用较为新且长期支持(LTS)的 CentOS 版本。
✅ 推荐使用的 CentOS 版本:
🟢 CentOS Stream 8 或 CentOS Stream 9
- CentOS Stream 是 CentOS 的未来发展方向,它是一个上游开发分支,适用于希望紧跟 RHEL 前沿技术的用户。
- WordPress 完全可以在这些版本上运行,只要配置好 LAMP(Linux + Apache + MySQL/MariaDB + PHP)或 LNMP 环境即可。
- CentOS 8 已于 2021 年底停止维护,现在官方推荐使用 CentOS Stream 8 或 9。
⚠️ 不推荐使用 CentOS 7
- CentOS 7 已于 2024 年 6 月结束生命周期(EOL),不再获得安全更新和支持。
- 虽然仍然可以安装 WordPress,但存在安全隐患,不建议用于生产环境。
📦 WordPress 对系统的基本要求(以最新版本为准)
WordPress 自身对操作系统没有特殊要求,但它依赖以下组件:
| 组件 | 最低推荐版本 |
|---|---|
| PHP | 8.0 或更高 |
| MySQL | 5.6 / MariaDB 10.1+ |
| Web服务器 | Apache 2.4 或 Nginx |
| HTTPS 支持 | 推荐启用 SSL/TLS |
🛠️ 在 CentOS 上安装 WordPress 的常见方式
-
手动安装 LAMP 环境:
- 安装 Apache、MariaDB、PHP 及其扩展
- 下载并配置 WordPress 源码
- 设置数据库和虚拟主机
-
使用宝塔面板等工具一键部署
-
使用 Docker 部署 WordPress 容器化应用
🧪 示例:在 CentOS Stream 9 上安装 WordPress
# 安装 EPEL 和 Remi 仓库
sudo dnf install epel-release -y
sudo dnf install https://rpms.remirepo.net/enterprise/remi-release-9.rpm -y
# 启用 PHP 8.2 模块
sudo dnf module enable php:8.2 -y
# 安装 LAMP 组件
sudo dnf install httpd mariadb-server mariadb php php-cli php-mysqlnd php-curl php-gd php-mbstring php-xml unzip wget -y
# 启动 MariaDB 和 Apache
sudo systemctl start httpd mariadb
sudo systemctl enable httpd mariadb
# 配置 MariaDB 安全设置
sudo mysql_secure_installation
# 创建 WordPress 数据库和用户
mysql -u root -p -e "CREATE DATABASE wordpress; CREATE USER 'wordpress'@'localhost' IDENTIFIED BY 'your_password'; GRANT ALL PRIVILEGES ON wordpress.* TO 'wordpress'@'localhost'; FLUSH PRIVILEGES;"
# 下载并解压 WordPress
cd /var/www/
sudo wget https://wordpress.org/latest.zip
sudo unzip latest.zip
sudo chown -R apache:apache wordpress
sudo chmod -R 755 wordpress
# 创建 Apache 虚拟主机配置文件
echo "<VirtualHost *:80>
DocumentRoot /var/www/wordpress/
ServerName your_domain
<Directory /var/www/wordpress/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>" | sudo tee /etc/httpd/conf.d/wordpress.conf
# 重启 Apache
sudo systemctl restart httpd
然后通过浏览器访问 http://your_server_ip 开始 WordPress 安装向导。
📌 总结
| CentOS 版本 | 是否推荐 | 备注 |
|---|---|---|
| CentOS 7 | ❌ 不推荐 | 已停止支持 |
| CentOS 8 | ⚠️ 慎用 | 已停止维护,可用作临时环境 |
| CentOS Stream 8 | ✅ 推荐 | 稳定版,适合生产 |
| CentOS Stream 9 | ✅ 推荐 | 最新版,功能更强大 |
如需帮助搭建 WordPress 环境,欢迎继续提问!我可以提供完整脚本或一步步指导。
CLOUD技术博