如何将实时WordPress网站移动到本地服务器

After learning how easy it is to install WordPress on local server in Windows or Mac, some of our beginner level readers asked us how they can move their live WordPress site to local server. We have previously showed you how to move a a WordPress site from local server to live site. This article is an exact opposite of that. In this article, we will show you how to move a live WordPress site to local server.

在了解了在WindowsMac 上的本地服务器上安装WordPress的简易性之后,我们的一些初学者读者问我们如何将实时WordPress网站移动到本地服务器。 之前,我们已经向您展示了如何将WordPress网站从本地服务器移动到实时网站 。 本文与之完全相反。 在本文中,我们将向您展示如何将实时WordPress网站移至本地服务器。

为什么以及谁愿意将实时WordPress网站移至本地服务器? (Why and Who Would Want to Move a live WordPress Site to Local Server?)

A lot of people create a copy of their live site on local server to test new themes, plugins, or do development testing. This allows you to set up your theme with all your content and test all the features without worrying about breaking your site. Many users copy their site to local server to practice their WordPress and coding skills with actual site data.

很多人在本地服务器上创建其实时站点的副本,以测试新主题,插件或进行开发测试。 这使您可以设置所有内容的主题并测试所有功能,而不必担心会破坏您的网站。 许多用户将其站点复制到本地服务器,以使用实际站点数据练习其WordPress和编码技能。

Even though you can do all the testing with dummy content in WordPress, real site data gives you a better visual representation of how these changes will appear on your live site.

即使您可以使用WordPress中的虚拟内容进行所有测试,但实际站点数据仍可以使您更好地直观表示这些更改将如何显示在您的实时站点上。

Important: Whether you are moving your WordPress site to a new domain, or from WordPress.com to self hosted WordPress, or to your localhost, it is highly recommended that you backup your entire website first. We recommend using BackupBuddy to create backups. You can also backup your site using BackWPUp, or create a manual backup.

重要提示 :无论您是将WordPress网站移至新域 ,还是从WordPress.com移至自托管的WordPress ,或移至本地主机,强烈建议您首先备份整个网站。 我们建议使用BackupBuddy创建备份。 您也可以使用BackWPUp备份站点,或创建手动备份

使用插件将实时WordPress网站移动到本地服务器 (Moving Live WordPress Site to Local Server using Plugin)

First thing you need to do is install and activate the Duplicator plugin on your live site. Duplicator plugin allows you to create duplicate package of your entire WordPress site. It can be used to move your WordPress site to a new location, and can also be used as a backup plugin. Upon activation, the plugin adds a new “Duplicator” menu item in your WordPress admin sidebar. Clicking on it will take you to the packages screen of the plugin.

您需要做的第一件事是在实时站点上安装并激活Duplicator插件。 Duplicator插件可让您创建整个WordPress网站的重复包。 它可以用于将WordPress网站移动到新位置,也可以用作备份插件。 激活后,该插件会在WordPress管理员侧边栏中添加一个新的“ Duplicator”菜单项。 单击它将带您到插件的软件包屏幕。

Create a new package in the Duplicator plugin

To create a new package, you need to click on the create new package button. Duplicator will start creating a package of your entire WordPress site. This may take a while, depending on how much data you have on your live site. Once finished it will redirect you to the packages screen, showing newly created package with a installer file. To move your site you need to download both, the zip package, as well as the installer file to your computer.

要创建一个新包,您需要单击创建新包按钮。 Duplicator将开始创建整个WordPress网站的软件包。 这可能需要一段时间,具体取决于您的实时站点上有多少数据。 完成后,它将重定向到软件包屏幕,显示带有安装程序文件的新创建的软件包。 要移动您的站点,您需要将zip软件包以及安装程序文件都下载到计算机上。

Duplicator Zip Package and Installer file

Your local server site will need a new database, so you need to create a database on your local server using phpMyAdmin. Once you have created the database you need to copy paste the package and install file to an empty folder in your local server’s web directory. To run the installation script, you need to open the install file in your web browser. For example if you pasted both files in /test-site/ folder you will access them in your browser by visiting http://localhost/test-site/install.php. You will now see the Duplicator installation script like this:

您的本地服务器站点将需要一个新的数据库,因此您需要使用phpMyAdmin在本地服务器上创建一个数据库。 创建数据库后,需要复制粘贴软件包并将安装文件安装到本地服务器的Web目录中的空文件夹中。 要运行安装脚本,您需要在Web浏览器中打开安装文件。 例如,如果您将两个文件都粘贴到/test-site/文件夹中,则可以通过访问http://localhost/test-site/install.php在浏览器中访问它们。 现在,您将看到这样的Duplicator安装脚本:

Running duplicator install script on localserver

On this screen, you need to provide your local server’s database information. The host is usually the localhost. If you have not created a new user for MySQL on your site, then your username would be root. If you are using a password for the root user then enter that password, otherwise leave it blank. Lastly, you need to enter the database name you just created.

在此屏幕上,您需要提供本地服务器的数据库信息。 主机通常是本地主机。 如果您尚未在站点上为MySQL创建新用户,则您的用户名将为root。 如果您为root用户使用密码,请输入该密码,否则将其留空。 最后,您需要输入刚创建的数据库名称。

The installer will now extract your database and WordPress files from the zip package and import them. Depending on the size of package, this may take a while. Once the installer has extracted the files and imported database, it will redirect you to the update page.

现在,安装程序将从zip包中提取数据库和WordPress文件,并将其导入。 根据包装的大小,这可能需要一段时间。 一旦安装程序提取了文件并导入了数据库,它将把您重定向到更新页面。

Updating URLs in Duplicator plugin for WordPress

On the update page, you need to provide the URL of your live site and the URL of the site on your local server. The plugin will automatically detect these values make sure they are correct and then click on the update button. Duplicator plugin will now update URLs in your database.

在更新页面上,您需要提供实时站点的URL和本地服务器上站点的URL。 插件将自动检测这些值,确保它们正确无误,然后单击“更新”按钮。 现在,Duplicator插件将更新数据库中的URL。

Succesfully copied your live site to local server

That’s all, you have successfully moved your live site to local server. The installer will show you a success page. You would also need to update permalinks on your local server site and delete the installer file and package.

就是这样,您已经成功将活动站点移到了本地服务器。 安装程序将显示成功页面。 您还需要更新本地服务器站点上的永久链接,并删除安装程序文件和软件包。

手动将实时WordPress网站移动到本地服务器 (Manually Move a Live WordPress Site to Local Server)

In case the plugin does not work for you, then you can always manually move your live site to local server. The first thing you would need is to back up your website manually. We have a tutorial on how to backup your WordPress database manually. We recommend using phpMyAdmin to export your WordPress database.

如果该插件对您不起作用,那么您始终可以手动将实时站点移至本地服务器。 您需要做的第一件事是手动备份您的网站。 我们有一个有关如何手动备份WordPress数据库的教程。 我们建议使用phpMyAdmin导出WordPress数据库。

To export your live site’s WordPress database, you need to log into your cPanel dashboard and click on phpMyAdmin. Inside phpMyAdmin you need to select the database you want to export and then click on the export tab on the top.

要导出实时站点的WordPress数据库,您需要登录到cPanel仪表板并单击phpMyAdmin。 在phpMyAdmin内部,您需要选择要导出的数据库,然后单击顶部的“导出”选项卡。

Export tab in phpMyAdmin

phpMyAdmin will now ask you to choose either quick or custom export method. We recommend using custom method and choosing zip as the compression method. Sometimes WordPress plugins can create their own tables inside your WordPress database. If you are not using that plugin anymore, then the custom method allows you to exclude those tables. Leave rest of the options as they are and click on the Go button to download your database backup in zip format.

phpMyAdmin现在将要求您选择快速或自定义导出方法。 我们建议使用自定义方法并选择zip作为压缩方法。 有时WordPress插件可以在WordPress数据库中创建自己的表。 如果您不再使用该插件,则自定义方法允许您排除那些表。 其余选项保持不变,然后单击“执行”按钮以zip格式下载数据库备份。

Custom export options in phpMyAdmin

Once you have downloaded your database backup, the next step is to download your WordPress files. To do that you need to connect to your WordPress site using an FTP client like Filezilla. Download all your WordPress files and folder to your computer. Downloading all your files may take a while depending on how much data you have on your website.

下载数据库备份后,下一步就是下载WordPress文件。 为此,您需要使用FTP客户端(如Filezilla)连接到WordPress站点。 将所有WordPress文件和文件夹下载到计算机上。 下载所有文件可能需要一段时间,具体取决于您网站上的数据量。

Download all your WordPress files and folders through FTP

After downloading your WordPress files, if you downloaded all your files and not just the wp-content directory then simply copy paste these files in your local server folder where you want to install WordPress.

下载完WordPress文件后,如果您下载了所有文件而不仅仅是wp-content目录,则只需将这些文件复制粘贴到您要安装WordPress的本地服务器文件夹中即可。

On your local server, you need to create a database for your WordPress site. To do that you need to open http://localhost/phpmyadmin/ in your web browser and create a new database. After creating the database click on the Import tab on top. On the next screen you need to click on the Choose File button to select the WordPress database export file you downloaded earlier, and then click on the Go button. phpMyAdmin will now import your database and will show you a success message when it is done.

在本地服务器上,您需要为WordPress网站创建一个数据库。 为此,您需要在Web浏览器中打开http://localhost/phpmyadmin/并创建一个新数据库。 创建数据库后,单击顶部的“ 导入”选项卡。 在下一个屏幕上,您需要单击“ 选择文件”按钮以选择之前下载的WordPress数据库导出文件,然后单击“执行按钮。 phpMyAdmin现在将导入您的数据库,并在完成后向您显示成功消息。

Importing your database through phpMyAdmin

Now that your database is all set up, you need to update the URLs inside your WordPress database referencing to your live site. You can do this by running an SQL query in phpMyAdmin. Make sure you have selected your local site’s database and then click on SQL. In phpMyAdmin’s SQL screen copy and paste this code, make sure that you replace example.com with your live site’s URL and localhost/test-site with the local server URL of your site.

现在您的数据库已全部设置完毕,您需要更新WordPress数据库中指向实际站点的URL。 您可以通过在phpMyAdmin中运行SQL查询来做到这一点。 确保选择了本地站点的数据库,然后单击SQL。 在phpMyAdminSQL屏幕中,复制并粘贴此代码,请确保将example.com替换为实时站点的URL,并将localhost / test-site替换为站点的本地服务器URL。


UPDATE wp_options SET option_value = replace(option_value, 'http://www.example.com', 'http://localhost/test-site') WHERE option_name = 'home' OR option_name = 'siteurl';
 
UPDATE wp_posts SET post_content = replace(post_content, 'http://www.example.com', 'http://localhost/test-site');
 
UPDATE wp_postmeta SET meta_value = replace(meta_value,'http://www.example.com','http://localhost/test-site');

This query will replace refences to your live site’s URL from database and replace it with the localhost URL.

该查询将替换对数据库中实时站点URL的引用,并将其替换为localhost URL。

The final step is to update your local site’s wp-config.php file. You need to go to the folder where you installed WordPress on your local server and open wp-config.php file in a text editor like Notepad. Replace database name with the one you created in phpMyAdmin on your localhost. Replace the username with your local mysql username, usually it is root. If you have set password for mySQL user root on your localhost, then enter that password. Otherwise leave it empty and save your changes.

最后一步是更新本地站点的wp-config.php文件。 您需要转到本地服务器上安装WordPress的文件夹,并在文本编辑器(如记事本)中打开wp-config.php文件。 将数据库名称替换为您在localhost上的phpMyAdmin中创建的名称。 用本地mysql用户名替换用户名,通常是root。 如果您在本地主机上为mySQL用户root设置了密码,请输入该密码。 否则,将其留空并保存您的更改。


/** The name of the database for WordPress */
define('DB_NAME', 'database_name_here');

/** MySQL database username */
define('DB_USER', 'username_here');

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


That’s all your live site is now copied to your local server, and you are ready to test drive it. We hope that you found this tutorial helpful. If you have any questions or feedback, then please leave a comment below.

这就是您的所有活动站点,现在已将其复制到本地服务器,您可以对其进行驱动器测试了。 我们希望您对本教程有所帮助。 如果您有任何疑问或反馈,请在下面发表评论。

翻译自: https://www.wpbeginner.com/wp-tutorials/how-to-move-live-wordpress-site-to-local-server/

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值