Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

AWS to VPS Migration: Step-by-Step Guide

· 8 min read · Home Tech

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

This guide walks you through migrating your workloads from Amazon Web Services (AWS) to a Virtual Private Server (VPS) provider. You'll learn how to export your data, set up your new environment, transfer files and databases, update DNS, and verify everything works—with minimal downtime. Before you start, you'll need access to your AWS console, SSH keys or passwords for your VPS, and a clear inventory of your current setup.

What You'll Need

  • Administrative access to your AWS account (IAM user with EC2, RDS, S3, and Route 53 permissions as applicable).
  • SSH client (e.g., OpenSSH, PuTTY) and your private key or password for both AWS and the new VPS.
  • A VPS plan from a provider of your choice (e.g., DigitalOcean, Linode, Vultr, Hetzner) with enough CPU, RAM, and storage to match your current usage.
  • A domain name registrar account where you can manage DNS records (or access to AWS Route 53 if you'll keep DNS there).
  • Backup of your AWS resources—ideally snapshots or exports—before making changes.
  • Basic familiarity with the Linux command line and your application stack (web server, database, etc.).

Step-by-Step

  1. Inventory your AWS resources. Log into the AWS console and list all EC2 instances, RDS databases, S3 buckets, Elastic IPs, security groups, and any other services you use. Note down instance types, storage sizes, and configuration details (e.g., web server, database engine, application settings). This inventory will be your migration checklist.
  2. Create backups of your data. For EC2 instances, create an AMI (Amazon Machine Image) or at least a snapshot of the EBS volumes. For RDS, take a manual snapshot or use the export to S3 feature if available. Download any S3 bucket contents to your local machine using the AWS CLI (aws s3 sync s3://your-bucket ./local-folder). This ensures you have a recoverable copy before you start.
  3. Set up your VPS. Provision a new VPS with your chosen provider. Choose an operating system that matches your AWS instance (e.g., Ubuntu 22.04, CentOS 7). Configure the VPS with a static IP address and ensure SSH access works. Create a non-root user with sudo privileges for daily use, and optionally set up a firewall (e.g., UFW) to allow only necessary ports (22, 80, 443).
  4. Install required software on the VPS. Install the same software stack you had on AWS: web server (Nginx, Apache), runtime (PHP, Python, Node.js), database (MySQL, PostgreSQL), and any other tools. Use your distribution's package manager. For example, on Ubuntu: sudo apt update && sudo apt install nginx php-fpm mysql-server.
  5. Transfer application files. Copy your application code and static files from AWS to the VPS. You can use scp or rsync. For example, from your local machine: rsync -avz -e ssh user@aws-ip:/var/www/html/ /var/www/html/ (run on the VPS). If you have a Git repository, simply clone it on the VPS. Ensure file permissions are correct.
  6. Migrate the database. If you used RDS, export the database using mysqldump or pg_dump (depending on engine). Run the dump on your local machine or directly from the VPS if you have network access to RDS. Then import the dump into your VPS database. For example, MySQL: mysqldump -h aws-rds-endpoint -u user -p dbname > db.sql, then on the VPS: mysql -u user -p dbname < db.sql. Update your application configuration to point to the new database host (usually localhost).
  7. Copy S3 data to VPS storage. If you used S3 for user uploads or static assets, download them to the VPS using aws s3 sync (after installing AWS CLI on the VPS) or via a tool like rclone. Place them in the appropriate directory (e.g., /var/www/html/uploads). Update any file paths in your application.
  8. Configure the web server and services. Set up your web server (Nginx/Apache) with virtual hosts or server blocks pointing to your application directory. Enable SSL with Let's Encrypt (e.g., certbot) if you had HTTPS. Configure any background workers (cron jobs, queue workers) using systemd or cron. Test your application locally by accessing the VPS IP address in a browser.
  9. Test thoroughly. Run through your application's core features: login, data retrieval, file uploads, and any external API calls. Check logs for errors (tail -f /var/log/nginx/error.log). Verify that the database connections work and that all environment variables are set correctly.
  10. Switch DNS. When you're confident the VPS works, update your DNS records. If you use Route 53, go to the hosted zone and change the A record for your domain to the VPS IP address. If you use another registrar, update the A record there. Set the TTL to a low value (e.g., 300 seconds) a few hours before the switch to speed up propagation.
  11. Monitor and finalize. After DNS propagates (usually 1-24 hours), monitor your site for errors. Once everything is stable, you can decommission your AWS resources: terminate EC2 instances, delete RDS instances, remove S3 buckets (after confirming you no longer need them), and release Elastic IPs. Keep backups for a while in case you need to roll back.

Common Mistakes

  • Forgetting to migrate cron jobs or background workers. These often live outside the web root and are easy to miss. List all cron jobs (crontab -l) and systemd services on AWS and recreate them on the VPS.
  • Hardcoded AWS endpoints or IPs in configuration files. Search your codebase for references to RDS endpoints, S3 bucket URLs, or instance IPs and replace them with new VPS values.
  • Not updating security groups/firewall rules. On AWS, security groups may have allowed traffic from specific IPs. Ensure your VPS firewall allows the same traffic, especially for SSH and web ports.
  • Overlooking file permissions and ownership. When copying files with rsync, permissions may not be preserved correctly. Set proper ownership (e.g., www-data for web files) and permissions (e.g., 755 for directories, 644 for files).
  • Switching DNS before testing. Always test your VPS using its IP address or a temporary hostname before pointing your domain to it. Otherwise, you'll have downtime if something is broken.

Tips

  • Use a staging subdomain. Create a subdomain like staging.yourdomain.com and point it to your VPS IP before the final switch. This lets you test with real domains and SSL certificates without affecting production.
  • Automate with configuration management. Tools like Ansible or Terraform can help you replicate your server setup consistently, reducing manual errors.
  • Keep your AWS environment running until DNS fully propagates. This allows you to roll back quickly if issues arise. Only shut down AWS resources after you've verified everything works for at least 24-48 hours.
  • Document your new server configuration. Write down the software versions, configuration paths, and any custom settings. This will help with future maintenance and troubleshooting.
  • Consider using a managed database service on the VPS provider (if available) to reduce database administration overhead, but be aware of potential compatibility issues.

Troubleshooting

  • Website shows 502 Bad Gateway. This usually means the web server can't reach the application server (e.g., PHP-FPM). Check that PHP-FPM is running (sudo systemctl status php-fpm) and that the socket/port configuration in your web server matches.
  • Database connection errors. Verify that your database service is running (sudo systemctl status mysql) and that the credentials in your application's config file are correct. Test the connection from the command line: mysql -u user -p -h localhost.
  • Files missing after transfer. If you used scp and the transfer was interrupted, re-run it. Use rsync with --progress to see errors. Check that the source paths are correct and that you have read permissions on the AWS instance.
  • Emails not sending. Many VPS providers block port 25 by default to prevent spam. If your application sends emails, you may need to use a third-party SMTP service (e.g., SendGrid, Mailgun) or request the provider to unblock the port (if allowed).
  • SSL certificate errors. If you used Let's Encrypt, ensure that the certificate is issued for the correct domain and that the web server is configured to use the right certificate paths. You can renew with sudo certbot renew.
  • DNS not propagating. Check your DNS records with a tool like dig or an online checker. Ensure TTLs are not too high (set to 300 seconds before the switch). If you're using Route 53, confirm that the hosted zone is active and the record is correct.

Frequently Asked Questions

How long does the migration take?

It depends on the size of your data and the complexity of your setup. A simple website with a small database can be migrated in a few hours, while a large application with multiple services might take a few days. Plan for at least a weekend to avoid downtime during business hours.

Can I keep using AWS for DNS after migrating?

Yes, you can keep your DNS in Route 53 and simply change the A record to point to your VPS IP. This is often easiest because you don't have to move DNS management. Just update the record and wait for propagation.

What happens to my AWS resources after the migration?

After you're confident the VPS works, you should terminate EC2 instances, delete RDS databases, and remove S3 buckets to stop incurring charges. However, keep backups (AMIs, snapshots) for at least a week in case you need to roll back.

Do I need to change my application code?

Usually not, unless you were using AWS-specific services like S3 SDKs or RDS endpoints. You'll need to update configuration files to point to the new database host and file storage paths. If you used S3 for file storage, you might need to switch to local storage or a compatible object storage service.

Will my site have downtime during the switch?

If you follow the steps correctly, downtime can be minimal—just the time it takes for DNS to propagate (usually under an hour). You can reduce it further by lowering the TTL before the switch and using a load balancer to route traffic to both environments temporarily.

Can I migrate from AWS to a VPS without any downtime?

Yes, with careful planning you can achieve near-zero downtime. Use a reverse proxy or load balancer to route traffic to both AWS and the VPS during the transition, then gradually shift traffic to the VPS. This requires more setup but is possible for most web applications.