DEV3 Technologies home

DEV3 Developer Forum

How do I migrate a WordPress site to a new host or domain without breaking links?

WordPress helpSolved0 views
dev3 ·

I need to move a site from shared hosting to a VPS and change from staging.example.com to example.com. What are the exact steps, and how do I fix URLs safely?

#wordpress#migration#database

0

1 reply

dev3 · Accepted answer

A migration is files plus database plus URL fix-up.

1. Export from the old host

# files
tar -czf site-files.tar.gz -C /path/to/public_html .
# database
mysqldump -u USER -p DBNAME > site.sql

2. Prepare the new host: create an empty database and user, PHP version and extensions matching the old site (mysqli, gd or imagick, mbstring, curl, zip).

3. Import

tar -xzf site-files.tar.gz -C /var/www/example.com
mysql -u NEWUSER -p NEWDB < site.sql

4. Edit wp-config.php: DB_NAME, DB_USER, DB_PASSWORD, DB_HOST.

5. Replace URLs with a serialization-aware tool. Never run a plain SQL REPLACE() over the database, because PHP serialized data stores string lengths and breaks.

wp search-replace 'https://staging.example.com' 'https://example.com' --all-tables --dry-run
wp search-replace 'https://staging.example.com' 'https://example.com' --all-tables
wp cache flush && wp rewrite flush

6. Test before switching DNS by adding the new IP to your local hosts file. Check permalinks, media, forms, checkout.

7. Cut over: lower DNS TTL a day earlier, switch the A record, keep the old host for a few days, and install the SSL certificate on the new server.

Pitfalls

  • Hard-coded old paths in .htaccess, or WP_HOME/WP_SITEURL constants overriding the database.
  • File ownership and permissions after extracting as root.
  • Email: SPF/DKIM records and SMTP settings differ per host.
  • Old domain 301 redirects to the new one if the domain changed, to keep SEO.
0

Your reply

Every post is reviewed by DEV3 before it appears. Usually reviewed within 24 hours.

Markdown supported. Use ``` for code blocks. Images are not allowed.