How to move a WordPress site to a new domain or server?

  1. Take a full backup (database and wp-content).
  2. Copy the files to the new server, and import the database there.
  3. Edit wp-config.php with the new database name, user, password and host.
  4. Replace the old domain with the new one in the database. Use WP-CLI, because it handles serialized data:
  5. Save Settings > Permalinks again, check the images and links, and set up 301 redirects from the old URLs.
Terminal output

$ wp post create –post_title="Link test" –post_content='<a href="http://example.com/about/">About</a>' –post_status=publish –porcelain
5
$ wp search-replace 'http://example.com' 'https://new-example.com' –dry-run –skip-columns=guid –report-changed-only
Table Column Replacements Type
wp_options option_value 2 PHP
wp_posts post_content 3 SQL
wp_users user_url 1 SQL
Success: 6 replacements to be made.

Remove --dry-run when you are happy with the report. Never use a plain SQL REPLACE on the database, because the values saved with serialize() will break. See WP-CLI and Backup and Update.


Learn more about the similar topics:
Tutorials
No Content Found.
Exercises & Assignments
No Content Found.
Interview Questions & Answers
No Content Found.