Wordpress 迁移到本地环境 [英] Wordpress migration to local environment

查看:31
本文介绍了Wordpress 迁移到本地环境的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

背景

我被指派更新 3rd 方 Wordpress 主题,第一个任务是将生产网站迁移到我的开发环境.

I've been assigned to update a 3rd party Wordpress theme and the first task was the migration of the production website to my development environment.

迁移

  1. 我已通过 ssh 连接到生产服务器,压缩了整个网站文件夹并与转储的数据库一起传输到我的本地环境.
  2. 我已经将它部署到一个 vagrant box 中,使用与生产服务器相同的灯配置.
  3. 我在开发环境中恢复的数据库中运行了以下更新.

:

UPDATE wp_options SET option_value = replace(option_value,    'http://production.com', 'http://dev.site') WHERE option_name = 'home' OR option_name = 'siteurl';

UPDATE wp_posts SET post_content = replace(post_content, 'http://production.com', 'http://dev.site');

UPDATE wp_postmeta SET meta_value = replace(meta_value,'http://production.com','http://dev.site');

问题

在我的开发环境中访问该网站时,我注意到许多生产短代码已损坏.

When accessing the website in my development environment I noticed that many of the production shortcodes are broken.

有什么想法吗?

推荐答案

大多数迁移中断都是由错误的序列化数据引起的.

Most migration breaks are caused by bad serialised data.

修复这些中断的最简单方法是强制重新创建数据.这可以通过强制插件将序列化数据重写到 MySQL 数据库来实现.

The easiest way to repair these breaks is to Force Recreate the data. This achievable by forcing the plugin to rewrite the serialised data to the MySQL database.

遵循这些步骤将有助于解决您可能遇到的大多数迁移错误:

  1. 停用重新激活您的所有插件
  2. 激活一个不同的(最好是默认/内置的)主题,然后重新激活你当前的主题.
  3. 前往设置 -> 永久链接,然后点击保存(保持所有设置相同)
  1. Deactivate and Reactivate all of your plugins
  2. Activate a different (preferrably a default / built-in) theme, and then reactivate your current theme.
  3. Head to Settings -> Permalinks and just click save (keep all your settings the same)

对于阅读此答案的其他人:重要的是要注意,如果您的 URL 更改并且您没有运行问题中提到的 SQL 修复

For anyone else reading this answer: It's important to note that almost all of this would be impossible if your URL changed and you did not run the SQL fix mentioned in the question

如果需要,我在下面添加了我自己的版本,您只需要记住替换 oldsite-url.comnewsite-url.com> 具有相关值.

If needed, I've added my own version of it below, you will just have to remember to replace the oldsite-url.com and newsite-url.com with relevant values.

如果有问题的数据库使用自定义表前缀(即不是wp_),您需要记住find -> replace

If the database in question uses a custom table prefix (i.e. not wp_), you will need to remember to find -> replace that as well.

这是 SQL 查询:

UPDATE wp_options SET option_value = replace(option_value, 'http://oldsite-url.com', 'http://newsite-url.com') WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_posts SET guid = REPLACE (guid, 'http://oldsite-url.com', 'http://newsite-url.com');
UPDATE wp_posts SET post_content = REPLACE (post_content, 'http://oldsite-url.com', 'http://newsite-url.com');
UPDATE wp_postmeta SET meta_value = REPLACE (meta_value, 'http://oldsite-url.com','http://newsite-url.com');

这篇关于Wordpress 迁移到本地环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆