将学校公网上的WordPress迁移到内网

因学校原部署WordPress的公网VPS明年可能不再续费,接到老师委托,需要在内网重新部署一套WordPress服务器,并将公网数据迁移到内网

我负责在内网搭建LNMP环境将WordPress数据迁移重新部署,以下是于内网服务器上的操作过程

全程操作记录

名称 版本
CentOS 7.2
WordPress 5.4.1-zh_CN
MySQL 5.7.30
Nginx 1.18.0
PHP 7.0.33
VSFTP 3.0.2

注:全文为带注释的,数据已脱敏

安装配置MySQL

参照官方文档

安装

# 安装MySQL on CentOS 7存储库
yum install https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm

# 选择存储库
yum-config-manager --disable mysql80-community
yum-config-manager --enable mysql57-community

# 安装MySQL
yum install mysql-community-server

# 服务
systemctl start mysqld
systemctl enable mysqld

配置

-- 修改root默认密码
ALTER USER 'root'@'localhost' IDENTIFIED BY '********';

-- 创建数据库
create database wordpress character set utf8mb4;

-- 创建用户并授权访问数据库
grant all on wordpress.* to 'wordpress'@'localhost' identified by '********';

安装Nginx

安装Nginx

添加Nginx存储库/etc/yum.repos.d/nginx.repo

cat > /etc/yum.repos.d/nginx.repo << EOF
[nginx]
name=nginx repo
baseurl=https://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1
EOF

使用包管理器安装Nginx

yum install nginx

安装配置PHP

参照非官方文档

安装

# 安装并启用存储库
yum install epel-release yum-utils
yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm

# 安装php及模块
yum install php php-fpm php-mysql php-mbstring

# 设置目录权限
chown -R nginx:nginx /var/lib/php/

配置

编辑php-fpm默认配置/etc/php-fpm.d/www.conf

; 将默认用户从apache改成nginx
user = nginx
group = nginx

; 基于本博客的预计并发量较低,我选择unix socket,而非tcp socket,可以降低额外的开销
listen = /run/php-fpm/www.sock
listen.owner = nginx
listen.group = nginx

启动服务

systemctl start php-fpm
systemctl enable php-fpm

配置Nginx

http{
# ......
server {
listen 80;
server_name 192.168.*.*;
root /var/www/wordpress;
index index.html index.php;

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

}
location ~ \.php$ {
fastcgi_pass unix:/run/php-fpm/www.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
}

部署WordPress

下载WordPress

wget https://cn.wordpress.org/latest-zh_CN.zip

解压后将目录下的wp-config-sample.php重命名为wp-config.php并编辑

# 数据库名称
define( 'DB_NAME', 'wordpress' );
# 数据库用户名
define( 'DB_USER', 'wordpress' );
# 数据库用户密码
define( 'DB_PASSWORD', '********' );
# 数据库IP,默认
define( 'DB_HOST', 'localhost' );
# 数据库字符集
define( 'DB_CHARSET', 'utf8mb4' );

# 从https://api.wordpress.org/secret-key/1.1/salt/生成一组安全密钥
define('AUTH_KEY', '********');
define('SECURE_AUTH_KEY', '********');
define('LOGGED_IN_KEY', '********');
define('NONCE_KEY', '********');
define('AUTH_SALT', '********');
define('SECURE_AUTH_SALT', '********');
define('LOGGED_IN_SALT', '********');
define('NONCE_SALT', '********');

# WordPress对于主题或插件的安装不再需要FTP,而是通过PHP直接操作
define("FS_METHOD","direct");

移动目录并修改权限

cp -r wordpress /var/www/
chown -R nginx:nginx /var/www/wordpress/

启用nginx服务

systemctl start nginx
systemctl enable nginx

添加防火墙规则

firewall-cmd --add-service=http --zone=public
firewall-cmd --add-service=http --zone=public --permanent

从Web页面配置

浏览器访问http:/192.168.*.*/wp-admin-install.php进行安装初始化

登录管理后台

发现主题与插件页面出现”无法建立到WordPress.org的安全连接”的问题,获取api.wordpress.org的IP地址写入hosts,解决

安装Import Export WordPress Users插件,在原服务器使用这个插件将用户信息导出,在新服务器使用插件将用户信息导入

从管理菜单-工具-导入,安装WordPress,将原服务器导出的文档内容导入新服务器并分配数据对应的用户

从原服务器上的wp-content目录 拷贝到新服务器

以上,迁移数据内网重新部署WordPress完毕

文章作者: 黑小白
文章链接: http://blog.heixb.top/posts/b9a5/
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 许可协议。转载请注明来自 黑小白的博客