The Wild

VPS Migration: Step-by-Step Guide

· 5 min read · Mammals

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

Migrating from one VPS to another means moving your websites, databases, and server configuration from an old server to a new one. This guide covers the standard process: backing up, transferring files and databases, updating DNS, and verifying everything works. You'll need SSH access to both servers, the new server's IP address, and a domain name you control (for DNS changes).

What You'll Need

  • SSH access to both the old and new VPS (root or sudo privileges).
  • The IP address and login credentials for the new VPS.
  • Access to your domain registrar or DNS provider (to change DNS records).
  • A local machine with SSH client (like terminal on macOS/Linux, or PuTTY on Windows).
  • Optional: a temporary subdomain or test URL to verify the new server before switching DNS.

Step-by-Step

  1. Prepare the new VPS. Log into the new server via SSH and update the operating system. For Ubuntu/Debian: apt update && apt upgrade -y. For CentOS/Rocky: yum update -y. Install the same software stack you use on the old server (e.g., Nginx, Apache, MySQL, PHP).
  2. Create a full backup on the old server. Compress your web root (e.g., /var/www) and any configuration files (e.g., /etc/nginx or /etc/apache2). Use tar -czf backup.tar.gz /var/www /etc/nginx (adjust paths). Also dump all databases: mysqldump --all-databases > all-databases.sql (or use pg_dump for PostgreSQL).
  3. Copy backups to the new server. Use scp from your local machine: scp user@old-server-ip:~/backup.tar.gz . then scp backup.tar.gz user@new-server-ip:~/. Alternatively, use rsync directly between servers if you have SSH keys set up: rsync -avz -e ssh /var/www/ user@new-server-ip:/var/www/.
  4. Restore files on the new server. Extract the backup archive to the appropriate location. For example: tar -xzf backup.tar.gz -C / (careful with paths). Ensure file permissions and ownership are correct (e.g., chown -R www-data:www-data /var/www).
  5. Import databases. On the new server, run: mysql -u root -p < all-databases.sql. Verify the databases exist and are accessible. Update database connection strings in your application config files if the database user/password changed.
  6. Configure web server and services. Copy or recreate your virtual host configurations. Enable the sites with a2ensite (Apache) or ln -s for Nginx. Restart services: systemctl restart nginx or systemctl restart apache2. Test that your website loads locally on the new server by accessing it via the new IP (e.g., curl http://new-server-ip).
  7. Update DNS records. Go to your DNS provider and change the A record for your domain to the new server's IP address. If you use subdomains, update those as well. Note that DNS propagation can take anywhere from a few minutes to 48 hours.
  8. Test thoroughly. Once DNS propagates, visit your site using your domain name. Check all pages, forms, and database-driven features. Also test email sending if your server handles mail (SMTP).
  9. Monitor and switch over. Keep the old server running for a few days. Monitor your new server's logs for errors. After you're confident everything works, you can cancel the old VPS.

Common Mistakes

  • Forgetting to update database credentials in application config files after moving.
  • Not checking file permissions – files may be owned by the wrong user, causing 500 errors.
  • Copying configuration files with absolute paths that differ between servers (e.g., PHP-FPM socket paths).
  • Changing DNS before the new server is fully tested – leads to downtime.
  • Not backing up everything – missing cron jobs, SSL certificates, or environment variables.
  • Forgetting to update firewall rules on the new server, blocking ports 80/443.

Tips

  • Use a staging subdomain like staging.yourdomain.com pointing to the new server's IP to test before switching the main domain.
  • Keep a copy of your backups on your local machine as an extra safety net.
  • If you use SSL certificates, either copy the certificate files or use a tool like Certbot to issue new ones on the new server.
  • Document your server configuration (installed packages, custom settings) to make future migrations easier.
  • Use rsync instead of scp for large file transfers – it resumes interrupted transfers and is faster.
  • Test the new server with a temporary hostname or by editing your local hosts file to point the domain to the new IP before DNS changes.

Troubleshooting

If something goes wrong, here's what to do:

  • Website shows 500 error: Check the web server error logs (/var/log/nginx/error.log or /var/log/apache2/error.log). Common causes are file permission issues or missing PHP extensions.
  • Database connection refused: Verify MySQL is running (systemctl status mysql), and that the database user has permissions for the new server's host.
  • DNS not resolving: Use dig yourdomain.com to check propagation. If it still shows old IP, wait longer or check your registrar's nameservers.
  • Files missing after restore: Double-check the tar command's paths – if you used absolute paths, extract with -C / to restore to the same location.
  • SSL certificate errors: Re-issue certificates with Certbot: certbot --nginx -d yourdomain.com (or --apache).
  • Email not working: If you use local mail, check that Postfix or Exim is running and that the hostname is set correctly.

Frequently Asked Questions

How long does VPS migration take?

Typically a few hours if you're familiar with the process. The actual transfer time depends on the size of your data and the speed of your servers' network connection.

Do I need to change my DNS if the IP address is the same?

No, if the new VPS has the same IP as the old one (unlikely but possible with IP reassignment), you don't need to change DNS. Otherwise, yes.

Can I migrate without downtime?

Yes, by using a staging subdomain and testing before switching DNS. You can also use a load balancer or reverse proxy to minimize downtime, but that's more complex.

What about my SSL certificates?

You can copy the certificate files (usually in /etc/letsencrypt or /etc/ssl) or issue new ones using Certbot on the new server. Copying is faster but certificates may expire; reissuing is cleaner.

Is it safe to cancel the old VPS after migration?

Yes, but wait at least 48 hours after DNS changes to ensure everything is stable. Keep the old server running until you're sure no other services (like email) depend on it.

What if I forget to migrate a cron job?

Check crontab -l on the old server and recreate those entries on the new server. Also check /etc/cron.d for system-wide jobs.