简体   繁体   English

WordPress-从一台主机转移到另一台主机

[英]WordPress - moving from one host to another

I am trying to move a WordPress installation from one server to another one, including all of the SQL data, and the file-system data (photos,template files). 我正在尝试将WordPress安装从一台服务器移动到另一台服务器,包括所有SQL数据和文件系统数据(照片,模板文件)。

I just have a problem changing the URLs in the database, since I need to replace the new URL with the old one. 我只是在更改数据库中的URL时遇到问题,因为我需要用旧的URL替换新的URL。

I would love to have some suggestions about how can I replace the URLs (maybe there's a rplace statement in SQL?) 我很想就如何替换URL提出一些建议(也许在SQL中有一个rplace语句?)

Thanks in advance. 提前致谢。

Edit 5/16/2015 编辑5/16/2015

It's much better to use interconnectit.com WordPress Serialized PHP Search Replace Tool to find/replace URLs in the database and to correctly deserialize/reserialize that data. 最好使用interconnectit.com WordPress序列化的PHP搜索替换工具来查找/替换数据库中的URL,并正确地反序列化/重新序列化该数据。 Doing a find/replace in a text dump or with the UPDATE queries below will break serialized data. 在文本转储或下面的UPDATE查询中查找/替换将破坏序列化的数据。


Several easy ways: How to Move WordPress Blog to New Domain or Location » My Digital Life : 几种简单的方法: 如何将WordPress博客移动到新的域或位置»我的数字生活

UPDATE wp_options SET option_value = replace(option_value, 
'http://www.old-domain.com', 'http://www.new-domain.com')
 WHERE option_name = 'home' OR option_name = 'siteurl';

and others: How to Find and Replace Text in WordPress MySQL Database using SQL When Changing Domains » My Digital Life 等: 更改域时如何使用SQL在WordPress MySQL数据库中查找和替换文本»我的数字生活

Search RegEx « WordPress Plugins for grepping through posts and pages as a WP plugin-based way to replace image and other URLs in posts and pages. 搜索RegEx«WordPress插件 ,以基于WP插件的方式遍历帖子和页面,以替换帖子和页面中的图像和其他URL。

And there's Moving WordPress « WordPress Codex. 还有移动的WordPress«WordPress Codex。

One thing to be aware of is that WordPress stores some of it's data using serialised arrays (some plugins in particular, such as cforms, do this). 要注意的一件事是,WordPress使用序列化数组存储了其中的一些数据(特别是某些插件,例如cforms,就是这样做的)。

In instances where the site URL data may be serialised, simply updating the site URL text can change the length of data in the serialised string, corrupting the data and breaking things. 在站点URL数据可以序列化的情况下,只需更新站点URL文本即可更改序列化字符串中数据的长度,从而破坏数据并破坏内容。

Interconnectit have a php script that takes serialisation into account when doing a search replace in the WordPress database. Interconnectit有一个php脚本,在WordPress数据库中进行搜索替换时,会考虑序列化 Github repo of the script here . Github的脚本回购在这里

I have used this script in numerous WordPress migrations and it has been a lifesaver for me. 我已经在许多WordPress迁移中使用了此脚本,这对我来说是一个救生员。

You could simply dump the mySQL in a flat file and open it up in your favorite editor. 您只需将mySQL转储到平面文件中,然后在您喜欢的编辑器中将其打开。 Than do a find and replace for fully qualified domain name if you are literally change domains. 如果您实际上是在更改域名,则不要查找并替换完全限定的域名。 That should take care of WordPress specific URL settings as well, so all your links in pages, posts, sidebars etc. will work. 那也应该注意WordPress特定的URL设置,因此页面,帖子,侧边栏等中的所有链接都可以使用。 Also be sure to change the local path's recorded in the DB to reflect what the new ones will be as well. 另外,请确保更改数据库中记录的本地路径,以反映新路径也将是什么。

Once your done import the mySQL file in to the new DB and have at it. 完成后,将mySQL文件导入到新数据库中并使用它。 If something when wrong in transit than you'll definitely know. 如果在运输过程中出现错误,您肯定会知道。 :) :)

This is a really straight forwarded procedure with no frills but extremely detailed for newbies 这是一个非常简单的过程,没有多余的装饰,但是对于新手来说非常详细

  • Make a full wordpress backup from your local server/host using cpanel. 使用cpanel从本地服务器/主机进行完整的wordpress备份。 (wp + db) (wp + db)
  • download the backup1.tar.gz generated 下载生成的backup1.tar.gz
  • Install a new wp site (default theme) on the target host. 在目标主机上安装一个新的wp站点(默认主题)。 Same release, please! 请发布相同的版本!
  • warning: If they are different, leverage both releases. 警告:如果它们不同,请同时使用两个版本。
  • Make a full wordpress backup from your target host using cPanel. 使用cPanel从目标主机进行完整的wordpress备份。 (wp + db) (wp + db)
  • download the backup2.tar.gz generated 下载生成的backup2.tar.gz
  • Additionally backup (export) wp-admin and wp-users target mysql backups; 另外,备份(导出)wp-admin和wp-users以mysql备份为目标; save them for future use ahead. 保存它们以备将来使用。
  • enter target host cPanel > file Manager > enter wp diretory > clear all files 输入目标主机cPanel>文件管理器>输入wp目录>清除所有文件
  • upload local host wp backup1.tar.gz files to target host wp directory > extract files 将本地主机wp backup1.tar.gz文件上传到目标主机wp目录>提取文件
  • copy wp-config.php file from backup2.tar.gz file 从backup2.tar.gz文件复制wp-config.php文件
  • paste overriding wp-config.php file on target host wp directory 在目标主机wp目录上粘贴覆盖的wp-config.php文件
  • enter target host > cpanel > phpmyAdmin > find mySQL BD name of your target wp host and drop all tables. 输入目标主机> cpanel> phpmyAdmin>查找目标wp主机的mySQL BD名称,并删除所有表。
  • restore (import) local wp using backup1.tar.gz softsql.sql file to mySQL db on target host 使用backup1.tar.gz softsql.sql文件将本地wp还原(导入)到目标主机上的mySQL db
  • drop wp-admin and wp-users tables after restore. 还原后删除wp-admin和wp-users表。 Restore (import) wp-admin and wp-users you saved before. 恢复(导入)之前保存的wp-admin和wp-user。 This will guarantee target wp authentication when entering target host wp administrative tasks. 输入目标主机wp管理任务时,这将确保目标wp身份验证。
  • test target host wp url 测试目标主机wp url
  • The wp-config.php copy/paste is to restore target host wp and mySQL original authentications. wp-config.php复制/粘贴用于还原目标主机wp和mySQL原始身份验证。
  • Test target wp at /wp-admin mode. 在/ wp-admin模式下测试目标wp。
  • that's it! 而已! Enjoy. 请享用。

MySQL中确实确实存在REPLACE()函数 ,但我建议您按照hsatterwhite的建议进行操作,并在重新导入之前将整个MySQL转储编辑为平面文件,这尤其重要,因为REPLACE()函数区分大小写。

I think the guy is talking about hard links in his page/ post content. 我认为那家伙正在谈论他的页面/帖子内容中的硬链接。 You need to apply @markratledge MySQL replace function link this... 您需要应用@markratledge MySQL替换功能链接此...

UPDATE wp_posts SET post_content = REPLACE(post_content, 'http://www.old-domain.com', 'http://www.new-domain.com');

This will replace all the links in you post/ page content... 这将替换您发布/页面内容中的所有链接...

1) in your current server, go to phpMyAdmin and export your database 1)在您当前的服务器中,转到phpMyAdmin并导出数据库

2) open the exported file in your fav code editor, find and replace in the whole document your ex base url ( http://www.exdomain.com ) with your new one ( http://www.newdomain.com ) 2)在您的收藏夹代码编辑器中打开导出的文件,在整个文档中查找您的ex base URL( http://www.exdomain.com )并替换为新的URL( http://www.newdomain.com

3) go to the new server, import the SQL file with phpMyAdmin 3)转到新服务器,使用phpMyAdmin导入SQL文件

4) change DB user/pass/host in your wp-config.php 4)在您的wp-config.php中更改数据库用户/通过/主机

5) transfer via ftp all the files from the old server to the new one 5)通过ftp将所有文件从旧服务器传输到新服务器

and you should be done. 并且应该完成。

If you also change the directory path: delete your .htaccess and let Wordpress generate a new one updating the permalink options in the back-end. 如果您还更改目录路径:删除您的.htaccess文件,并让Wordpress生成一个新文件,以更新后端的永久链接选项。

This has always worked for me, I use to do this when it's time to move a localhost installation to the final production server. 这一直对我有用,当我需要将localhost安装移动到最终生产服务器时,我通常会这样做。

Hope it helps. 希望能帮助到你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM