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?
DEV3 Developer Forum
How do I migrate a WordPress site to a new host or domain without breaking links?
Every post is reviewed first. Usually reviewed within 24 hours.
1 reply
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, orWP_HOME/WP_SITEURLconstants 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.