CentOS 7 LAMP快速部署WordPress指南
CentOS 7 使用LAMP架构部署WordPress
1. 修改主机名
hostnamectl set-hostname lamp.example.com
bash # 立即生效
2. 关闭防火墙和SELinux
systemctl stop firewalld
systemctl disable firewalld # 修正拼写错误(原文档为firewallld)
setenforce 0 # 临时关闭SELinuxvim /etc/selinux/config
SELINUX=enforcing 改为 SELINUX=disabled # 永久关闭
3.配置yum仓库
cd /etc/yum.repos.d/
#全部删除
rm -rf *
阿里云CentOS 7镜像复制安装
yum -y install epel-release
4. 时钟同步
yum -y install chrony
systemctl restart chronyd
systemctl enable chronyd
hwclock -w # 同步硬件时钟
5. 安装Apache与MariaDB
yum -y install httpd mariadb mariadb-server
6. 初始化MariaDB
systemctl start mariadb # 启动服务(原文档为restart)
systemctl enable mariadb # 设置开机自启
mysql_secure_installation # 运行安全配置脚本
配置说明:
- 设置root密码:
redhat
(生产环境建议使用强密码) - 移除匿名用户:Remove anonymous users?:
y
- 禁止root远程登录:Disallow root login remotely?:
n
- 移除测试数据库:Remove test database and access to it?:
y
- 重载权限表:Reload privilege tables now? :
y
7. 安装PHP
# 启用Remi仓库(PHP 7.4,更稳定且兼容WordPress)
yum -y install https://rpms.remirepo.net/enterprise/remi-release-7.rpm
yum -y install yum-utils
yum-config-manager --enable remi-php70 #启用php70# 安装PHP及扩展
yum -y install php php-cli php-fpm php-gd php-curl php-zip php-mbstring php-opcache php-intl php-mysqlnd
8. 配置PHP时区,将时区改成亚洲/上海
echo "date.timezone = Asia/Shanghai" >> /etc/php.ini # 追加时区配置
systemctl restart php-fpm
systemctl enable php-fpm
9. 配置Apache默认页
# 设置默认首页为index.php
vim /etc/httpd/conf/httpd.conf
<IfModule dir_module>DirectoryIndex index.html index.php
</IfModule># 创建测试页
echo "<?php phpinfo(); ?>" > /var/www/html/index.php# 启动服务
systemctl restart httpd
systemctl enable httpd
10. 测试LAMP环境
访问 http://服务器IP
,确认显示PHP信息页(如下图示)
✅ LAMP基础环境部署成功
11. 上传WordPress
yum -y install lrzszmkdir -p /opt/software # 创建软件目录
cd /opt/software
# 使用rz上传或wget下载(示例使用wget)
`将wordpress-6.5.5.tar.gz压缩包拖入进`
wget https://wordpress.org/wordpress-6.5.5.tar.gz
12. 解压并部署WordPress
yum -y install tartar -zxvf wordpress-6.5.5.tar.gz
#ls 查看解压完的包
cp -R wordpress /var/www/html/
13. 设置目录权限
chown -R apache:apache /var/www/html/wordpress # 属主属组
chmod -R 755 /var/www/html/wordpress # 建议755(原文档775权限过高)
14. 创建WordPress数据库
mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 12
Server version: 10.5.22-MariaDB MariaDB ServerCopyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.MariaDB [(none)]> create database wordpress_db;
Query OK, 1 row affected (0.000 sec)MariaDB [(none)]> create user 'wordpress_user'@'localhost' identified by 'redhat';
Query OK, 0 rows affected (0.001 sec)MariaDB [(none)]> grant all on wordpress_db.* to 'wordpress_user'@'localhost';
Query OK, 0 rows affected (0.001 sec)MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.000 sec)
15. 配置Apache虚拟主机
cp -p /usr/share/doc/httpd-2.4.6/httpd-vhosts.conf /etc/httpd/conf.d/ # 备份原配置vim /etc/httpd/conf.d/httpd-vhosts.conf # 新建虚拟主机配置
添加以下内容:
<VirtualHost 192.168.100.10:80>DocumentRoot "/var/www/html/wordpress"<Directory "/var/www/html/wordpress">Options Indexes FollowSymLinksAllowOverride All # 允许.htaccess覆盖配置Require all granted</Directory>
</VirtualHost>
16. 重启Apache服务
systemctl restart httpd
17. 完成WordPress安装
- 访问
http://服务器IP
- 按向导填写信息:
- 数据库名:
wordpress_db
- 用户名:
wordpress_user
- 密码:
redhat
- 数据库主机:
localhost
- 表前缀:
wp_
(默认)
- 数据库名:
- 点击提交 → 运行安装 → 设置站点标题/管理员账号
✅ WordPress部署完成!