wordpress网站迁移_如何将WordPress网站迁移到新域和托管

本文提供了一个详细的教程,说明如何将WordPress网站无压力地迁移到新的主机和域名。教程涵盖了停用插件、备份数据库和文件、手动和使用插件备份、更新wp-config.php文件、上传备份、修改URL、重定向设置以及一些实用技巧。遵循这些步骤,可以避免迁移过程中常见的错误和问题。
摘要由CSDN通过智能技术生成

wordpress网站迁移

Moving your WordPress site to a new host can be a bit stressful. If it’s not done properly, it can result in some annoying and unexpected errors. However, if it’s handled correctly, it should be a stress free experience.

将WordPress网站移至新主机可能会有些压力。 如果处理不正确,可能会导致一些烦人的意外错误。 但是,如果处理正确,应该是无压力的体验。

In this tutorial, I’ll demonstrate how to migrate a WordPress site to a new host and domain name, avoiding many of the common problems experienced with migrations.

在本教程中,我将演示如何将WordPress网站迁移到新的主机和域名,避免许多迁移时遇到的常见问题。

Note: There are many ways to approach a migration, in this tutorial I’ll be introducing you to a manual approach. It’s not always the easiest option, but once you understand how it works, you’ll be better equipped to tackle any problems you come across when moving sites. If you’re looking for a plugin to use to migrate, try this article that runs through five useful plugins for WordPress backup and migration, but keep in mind that understanding the manual approach presented here will help you considerably when using those.

注意:有很多方法可以进行迁移,在本教程中,我将向您介绍手动方法。 它并不总是最简单的选择,但是一旦您了解了它的工作原理,便可以更好地解决在移动网站时遇到的任何问题。 如果您正在寻找用于迁移的插件,请尝试这篇贯穿五个有用的WordPress备份和迁移插件的文章,但请记住,了解此处介绍的手动方法将在使用这些插件时为您提供很大帮助。

停用所有插件 (Deactivate All Plugins)

Before you begin, I’d recommend that you deactivate all plugins because, when moving a WordPress site to a new host, the things that are likely to fail are your WordPress plugins. WordPress itself is well designed to adapt to new changes, but the plugins might not be.

在开始之前,建议您停用所有插件,因为将WordPress站点移至新主机时,可能会失败的是您的WordPress插件。 WordPress本身经过精心设计,可以适应新的变化,但插件可能并非如此。

Therefore, to deactivate all activated plugins, go to the admin page -> Plugins -> Installed Plugins -> Mark all -> Bulk action -> Deactivate -> Apply

因此,要停用所有已激活的插件,请转到管理页面-> 插件 -> 已安装的插件 ->全部标记-> 批量操作 -> 停用 -> 应用

Deactivating Plugins

备份WordPress数据库和文件 (Backing up WordPress Database and Files)

It’s best practice to always backup your website before making any changes, and a WordPress migration is no exception. There are a couple of WordPress plugins for doing this, but a manual approach is best if you want to be in complete control of the process.

最佳做法是始终在进行任何更改之前始终备份您的网站,WordPress迁移也不例外。 有几个WordPress插件可以执行此操作,但是如果您希望完全控制该过程,则最好使用手动方法。

Now, I’ll show you how to backup your WordPress files and database with a manual approach, and also via a plugin.

现在,我将向您展示如何以手动方式以及通过插件备份WordPress文件和数据库。

手动备份 (Backing up Manually)

To back up your WordPress database manually: Log in to your phpMyAdmin, click on your WordPress database and select Export as shown in the image below.

要手动备份WordPress 数据库 :登录到phpMyAdmin,单击WordPress数据库,然后选择“ 导出” ,如下图所示。

Export Database

Ensure that you’re exporting in SQL Format and click Go. Your WordPress database will then be downloaded as a .sql file. I recommend that you save the downloaded SQL file to a special folder on your computer so that you can easily locate it later. You can also use the command line to export a copy of your database, you can find more information on that here.

确保你在SQL格式导出,然后单击Go。 然后,您的WordPress数据库将以.sql文件下载。 我建议您将下载SQL文件保存到计算机上的特殊文件夹中,以便以后可以轻松找到它。 您还可以使用命令行导出数据库的副本,您可以在此处找到更多信息

To backup your files manually: I would recommend that you download your complete WordPress installation folder so that you won’t lose anything.

手动备份文件 :建议您下载完整的WordPress安装文件夹,以免丢失任何内容。

Using any FTP/SFTP client like FileZilla, log in to your host by FTP/SFTP and download your htdocs or public_html folder (or anywhere your WordPress installation resides).

使用任何FTP / SFTP客户端(例如FileZilla) ,通过FTP / SFTP登录到主机,然后下载htdocs或public_html文件夹(或WordPress安装所在的任何位置)。

使用插件备份 (Backing up with a Plugin)

Download and install the UpdraftsPlus Backup and Restoration plugin. At the Installed Plugins page, locate the UpdraftsPlus plugin and activate it.

下载并安装UpdraftsPlus备份和还原插件。 在“已安装插件”页面上,找到UpdraftsPlus插件并激活它。

Once you have the plugin installed, at the admin page, go to Settings -> UpdraftsPlus Backups, and then click the Backup.

安装插件后,在管理页面上,转到“设置” ->“ UpdraftsPlus备份” ,然后单击“ 备份”

Updraft Plus

This might take a while depending on the size of your WordPress site, but once the process has been completed, click on the Exisiting Backups tab to download the backup to your computer and then you can move it to a special folder too.

这可能需要一段时间,具体取决于WordPress网站的大小,但是一旦完成该过程,请单击“ 现有备份”选项卡将备份下载到计算机,然后也可以将其移动到特殊文件夹中。

准备上传备份 (Preparing Your Backup for Upload)

Now that we have the backup, we need to modify a few things before we can move on to uploading our backup(s). Before proceeding, log in to phpMyAdmin of your new host and create a new database. Note down the name of the database, as you will be needing it later in this tutorial.

有了备份后,我们需要进行一些修改,然后才能继续上传备份。 在继续之前,登录到新主机的phpMyAdmin并创建一个新数据库。 记下数据库的名称,因为在本教程的后面部分将需要它。

更新wp-config.php文件 (Updating the wp-config.php file)

There is some information to be modified in our WordPress configuration file before moving on. Extract the ZIP archive of the WordPress installation folder you downloaded earlier, locate the wp-config.php file and open it for editing using your favorite text editor such as Notepad and Notepad++.

在继续之前,我们的WordPress配置文件中有一些信息需要修改。 提取先前下载的WordPress安装文件夹的ZIP归档文件,找到wp-config.php文件,然后使用您喜欢的文本编辑器(如Notepad和Notepad ++)将其打开以进行编辑。

Edit the lines below, replace with the details of your new host and save.

编辑下面的行,替换为新主机的详细信息并保存。

define('DB_NAME', 'replace_with_database_name_you_noted_down');

/** MySQL database username */

define('DB_USER', 'replace_with_new_host_mysql_user_name');

/** MySQL database password */
define('DB_PASSWORD', 'replace_with_new_host_mysql_password');

/** MySQL hostname */
define('DB_HOST', 'replace_with_new_mysql_host');

上载备份 (Uploading Your Backup)

We’re almost done. The next action to take is to upload your modified WordPress installation folder to the new host via FTP/SFTP.

我们快完成了。 下一步要执行的操作是通过FTP / SFTP将修改后的WordPress安装文件夹上传到新主机。

After uploading is completed, proceed to upload your database backup.

上传完成后,继续上传数据库备份。

To upload the database backup, log in to your phpMyAdmin in your new host and click the Import menu as shown below.

要上传数据库备份,请在新主机中登录到phpMyAdmin,然后单击“ 导入”菜单,如下所示。

Import

Select the SQL database backup and upload.

选择SQL数据库备份和上传。

更新WordPress主页URL和站点URL (Updating the WordPress Home URL and Site URL)

There are several ways to set your URL for WordPress, we’ll discuss a few common methods.

有几种方法可以为WordPress设置URL,我们将讨论一些常用方法。

If you’re moving to a new domain too, ensure you have successfully pointed your new domain to your hosting account (refer to your hosting support documentation for the exact details).

如果您也要移至新域,请确保已成功将新域指向托管帐户(有关详细信息,请参阅托管支持文档)。

使用wp-config.php (Using wp-config.php)

You can set your URLs by adding the following lines to wp-config.php, this overrides and will disable these options in the WordPress dashboard.

您可以通过在wp-config.php添加以下行来设置URL,这将覆盖并禁用WordPress仪表板中的这些选项。

define('WP_HOME','http://example.com');
define('WP_SITEURL','http://example.com');

The WordPress Codex has a good explanation of this.

WordPress Codex对此有很好的解释

使用WordPress主题functions.php文件 (Using a WordPress Theme functions.php File)

Paste the below lines in your active theme’s functions.php file immediately after the initial line, using the editor provided by an online FTP/SFTP client, or your preferred text editor.

line, using the editor provided by an online FTP/SFTP client, or your preferred text editor.将以下几行粘贴在活动主题的functions.php文件中的第一行之后line, using the editor provided by an online FTP/SFTP client, or your preferred text editor.

update_option ( 'siteurl', 'http://your_new_domain_name.com' );

update_option ( 'home', 'http://your_new_domain_name.com' );

Replace the http://your_new_domain_name.com with your new domain URL. The above code will automatically update the siteurl home option names with your new blog URL in the database. Visit your WordPress login or admin page and your site should work.

http://your_new_domain_name.com替换为新的域URL。 上面的代码将使用数据库中的新博客URL自动更新siteurl home选项名称。 访问您的WordPress登录名或管理页面,您的网站应该可以正常工作。

Once your site is back up, ensure that you delete the lines you added to your theme’s function.php file to prevent the updating each time your site is viewed.

备份站点后,请确保删除添加到主题的function.php文件中的行,以防止每次查看站点时进行更新。

手动更新WordPress主页URL和站点URL (Manually Updating the WordPress Home URL and Site URL)

To manually update your WordPress Home URL and Site URL, login back to your phpMyAdmin, open your WordPress database, click on the wp_options table and modify the values of the site_url and home column with your new URL.

要手动更新WordPress主页URL和站点URL,请重新登录phpMyAdmin,打开WordPress数据库,单击wp_options表,并使用新URL修改site_urlhome列的值。

Browse

Now that everything is working fine, go ahead and activate your necessary plugins. To do that, navigate to Plugins -> installed plugins, select activate from the Bulk action drop down and hit the Apply button.

现在一切正常,继续并激活必要的插件。 为此,请导航至插件 -> 已安装的插件 ,从批量操作下拉菜单中选择激活 ,然后点击Apply按钮。

To update your permalinks, go to Settings -> Permalinks, select your desired permalinks structure and Save Changes.

要更新您的永久链接,请转至设置 -> 永久链接 ,选择所需的永久链接结构并保存更改

301重定向设置 (301 Redirection Setup)

To transfer your old domains SEO juice (or SEO value) to the new one, it’s important that you set up a 301 redirect as follows.

要将旧的SEO汁(或SEO值)转移到新的SEO汁,请务必按以下步骤设置301重定向。

Open the .htaccess file in your old WordPress install folder and append the rewrite rules below so that anyone visiting your site using your old domain URL will be redirected to the new domain.

在旧的WordPress安装文件夹中打开.htaccess文件,并在下面附加重写规则,以便使用旧域名URL访问您网站的任何人都将被重定向到新域。

<IfModule mod_rewrite.c>

RewriteEngine On

RewriteCond %{HTTP_HOST}^olddomain.com$

[OR]

RewriteCond %{HTTP_HOST}^www.olddomain.com$

RewriteRule (.*)$ http://www.newdomain.com/$1 [R=301, L]

</IfModule>

一些有用的技巧 (Some Useful Tips)

php.ini and .htaccess files These files can contain settings that only work with your previous hosting, so if things don’t work, check these files first. Try renaming or commenting out various lines, and look for hard coded paths that might not exist on your new environment.

php.ini和.htaccess文件这些文件可以包含仅适用于以前的主机的设置,因此,如果不起作用,请首先检查这些文件。 尝试重命名或注释各行,并查找新环境中可能不存在的硬编码路径。

Caching Plugins Some caching plugins will modify your .htaccess or create files to absolute paths that might not exist on your new hosting setup.

缓存插件一些缓存插件会修改您的.htaccess或将文件创建为新主机设置中可能不存在的绝对路径。

Google reCaptcha Plugin In case you have any Google reCaptcha plugins installed, you should remember to get a new API key for your new domain, so that the plugin won’t find it difficult to display the reCaptcha.

Google reCaptcha插件如果您安装了任何Google reCaptcha插件,则应记住为新域获取一个新的API密钥 ,以使该插件不会很难显示reCaptcha。

Jetpack Plugin Also, if you have the Jetpack plugin installed, you should remember to re-connect your WordPress site to WordPress.com because you’ve moved to a new domain.

Jetpack插件此外,如果已安装Jetpack插件,则应记住将WordPress网站重新连接到WordPress.com,因为您已移至新域。

Genesis Club Lite Display Module If you have the Genesis Club Lite plugin installed, and the display module is activated, you should remember to change the domain part of your URL from the old domain to the new one. This is done at Genesis Club Lite -> Display -> Logo effect the change and save the changes.

Genesis Club Lite显示模块如果您安装了Genesis Club Lite插件,并且显示模块已激活,则应记住将URL的域部分从旧域更改为新域。 这是在Genesis Club Lite- > 显示 -> 徽标效果更改并保存更改后完成的。

结论 (Conclusion)

In this tutorial, I walked through how to move a WordPress site to a new host and how to change a domain name associated with it if you need to. If you’ve used absolute URLs in your content, you’ll need to update these too. Many plugins also need to be updated, but hopefully this points you in the right direction.

在本教程中,我逐步介绍了如何将WordPress网站移至新主机以及如何根据需要更改与之关联的域名。 如果您在内容中使用了绝对URL,则也需要更新它们。 许多插件也需要更新,但是希望这可以为您指明正确的方向。

Before you start any site migration, I’d highly recommend reading the WordPress Codex for even more details on the various processes.

在开始任何网站迁移之前,我强烈建议您阅读WordPress Codex,以获取有关各种流程的更多详细信息。

If you have any questions or suggestions please let us know in the comments below, it’s a broad topic so I’d love to hear your feedback and ideas on your own approach.

如果您有任何疑问或建议,请在下面的评论中告诉我们,这是一个广泛的主题,因此,我很想听听您对自己的方法的反馈和想法。

翻译自: https://www.sitepoint.com/how-to-migrate-a-wordpress-site-to-a-new-domain-and-hosting/

wordpress网站迁移

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值