WordPress迁移到新托管

无论你是因为性能缓慢、成本高或支持不佳而切换托管——错误进行的WordPress迁移可能会导致网站离线数小时,更糟糕的是,损害你的Google搜索排名。

本指南将引导你完成零停机WordPress迁移,涵盖三种完整方法:基于插件(Duplicator)、一体化插件和完全手动(FTP+数据库),附带迁移前后检查清单。

重要提示:迁移前始终创建完整备份。AsiaGB在每月1日和15日备份服务器,但在任何迁移前你应该有自己的备份。

1. 为什么要迁移WordPress?

迁移到新托管商的常见原因包括:

2. 迁移前检查清单

彻底的准备是任何迁移中最关键的部分。跳过这些步骤可能会导致难以修复的问题。

#任务优先级
1备份当前托管上的所有文件必需
2导出MySQL数据库(最新版本)必需
3记录所有凭证(数据库名、用户、密码)必需
4验证新主机上的PHP版本兼容性必需
5检查新托管上的可用存储推荐
6在迁移前24-48小时将DNS TTL降低到300秒推荐
7记录旧名称服务器,以防需要回滚推荐
8在迁移前更新所有插件和主题推荐

3. 方法1——使用Duplicator插件

Duplicator是最受欢迎的WordPress迁移插件,拥有超过150万个活跃安装。它对初学者来说是理想的,因为大多数步骤是自动化的。

Duplicator迁移步骤

  1. 从WordPress.org在你的旧托管上安装Duplicator插件
  2. 转到Duplicator → Packages → Create New
  3. 命名包,点击Next,等待系统扫描
  4. 如果所有检查都通过(绿色),点击Build——等待包完成
  5. 下载两个文件:installer.php和*_archive.zip
  6. 通过文件管理器或FTP将两个文件上传到新托管
  7. 在新主机上创建新数据库(DirectAdmin:Databases → MySQL Management)
  8. 浏览到http://yourdomain.com/installer.php并按照向导操作
  9. 输入新的数据库凭证,点击Test Database,然后Next
  10. 等待恢复完成,然后点击Admin Login

提示:Duplicator的免费版本支持最大500MB的包。对于较大的网站,使用Duplicator Pro或切换到手动方法。

4. 方法2——All-in-One WP Migration

All-in-One WP Migration是初学者的最简单选择,他们想避免直接接触数据库或FTP。

导出步骤

  1. 在旧托管上安装All-in-One WP Migration
  2. 转到All-in-One WP Migration → Export → Export To → File
  3. 等待.wpress文件生成,然后本地下载

导入步骤

  1. 在新托管上安装WordPress(通过DirectAdmin中的Softaculous)
  2. 在新的WordPress上安装All-in-One WP Migration
  3. 转到All-in-One WP Migration → Import → Upload
  4. 上传.wpress文件(你可能需要先增加上传限制)
  5. 等待导入完成——系统会将你重定向到再次登录

限制:All-in-One WP Migration的免费版本支持最大512MB的导入。对于较大的文件,你需要付费扩展或应使用手动方法。

10. 比较三种迁移方法

为了帮助你选择正确的方法,以下是所有三种方法在最重要的方面的并排比较。

对比维度 Duplicator All-in-One 手动FTP
难度简单非常简单中等
最大网站大小(免费版)500 MB512 MB无限制
需要FTP知识极少不需要需要
完全控制中等低完全
费用免费/专业版免费/扩展版免费
适合对象大多数网站初学者大型网站/高级用户

11. 迁移期间和迁移后的SEO保护

WordPress迁移操作不当可能导致排名暂时甚至永久下降。以下步骤可将SEO风险降到最低。

迁移前

迁移中

迁移后

12. 在新主机上设置SSL

迁移后最常被遗忘的步骤之一是在新主机上配置SSL。没有SSL,浏览器会显示"不安全"警告,Google也会降低该网站在搜索结果中的排名。

在DirectAdmin(AsiaGB)中设置SSL

  1. 登录DirectAdmin → 进入高级功能 → SSL证书。
  2. 选择Let's Encrypt免费自动证书。
  3. 勾选域名的www和非www版本。
  4. 点击保存——证书将在5–10分钟内签发。

在WordPress中强制使用HTTPS

获取SSL证书后,强制使用HTTPS,使所有HTTP请求自动重定向到HTTPS。将以下内容添加到.htaccess文件:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

或者,在"That's all, stop editing!"行之前,将以下内容添加到wp-config.php:

define('FORCE_SSL_ADMIN', true);
if (strpos($_SERVER['HTTP_X_FORWARDED_PROTO'], 'https') !== false)
    $_SERVER['HTTPS'] = 'on';

13. 迁移后的文件和文件夹权限

权限设置错误是迁移后WordPress出现异常的最常见原因之一——尤其是图片上传失败或插件无法正常工作的问题。

文件/文件夹 正确权限 说明
WordPress目录755所有者可执行,其他人只读
wp-content/uploads/755媒体上传需要可写权限
PHP/HTML文件644不允许其他人执行
wp-config.php600 或 640防止其他人读取密码
.htaccess644WordPress需要写入权限以更新固定链接

在DirectAdmin中,您可以通过文件管理器更改权限:右键点击文件或文件夹 → 更改权限。或者使用FTP客户端(如FileZilla):右键点击 → 文件权限。

5. Method 3 — Manual Migration (FTP + Database)

The manual method gives you complete control over every step and works for sites of any size.

Export Files

  1. Log in to the old hosting control panel (DirectAdmin or cPanel)
  2. Open File Manager, navigate to public_html
  3. Select all files → Compress to ZIP
  4. Download the ZIP file to your local computer

Export Database

  1. Open phpMyAdmin on the old hosting
  2. Select the WordPress database → click Export
  3. Choose SQL format, click Export → download the .sql file

Import to New Hosting

  1. Create a new database in DirectAdmin → Databases → MySQL Management
  2. Upload all files via FTP or File Manager to public_html
  3. Open phpMyAdmin on the new host → select new database → Import the .sql file

6. Update wp-config.php

After moving files and database, you must update wp-config.php with the new hosting credentials.

// Update these values in wp-config.php
define('DB_NAME',     'new_database_name');
define('DB_USER',     'new_database_user');
define('DB_PASSWORD', 'new_database_password');
define('DB_HOST',     'localhost'); // usually localhost

On DirectAdmin, you can edit wp-config.php through File Manager → right-click → Edit.

7. DNS Configuration and Testing

Before changing DNS, test the site on the new hosting using a local hosts file edit so only you see the new site while visitors still see the old one.

# Add to hosts file:
# Windows: C:\Windows\System32\drivers\etc\hosts
# Mac/Linux: /etc/hosts
123.456.789.000  yourdomain.com  www.yourdomain.com
# Replace 123.456.789.000 with the new hosting IP

Once testing confirms everything works correctly, update the nameservers at your domain registrar.

8. Post-Migration Testing Checklist

After DNS propagates (typically 1–48 hours), verify the following:

9. Common Problems and Solutions

White Screen or 500 Internal Server Error

Usually caused by PHP errors or plugin conflicts. Enable WordPress Debug Mode to read the error log and identify the cause.

Images Not Displaying

Verify that all files in wp-content/uploads/ were transferred completely, and check folder permissions (should be 755).

Redirect Loop

Check wp-config.php for correct HTTPS enforcement settings, and verify .htaccess redirect rules don't conflict with each other.

Plugins Behaving Unexpectedly

Some plugins store absolute paths in the database. Run a search-and-replace using the Better Search Replace plugin to update all old URLs to the new ones.

SEO Tip: After migration, re-submit your sitemap in Google Search Console and monitor the index status for the first week to confirm Google can still crawl and index your site fully.

WordPress Hosting That's Easy to Migrate To

AsiaGB Hosting uses DirectAdmin with Softaculous for easy WordPress installation. Starting at 500 THB/year with multi-PHP version support and free SSL certificates.

View Hosting Plans →