Website Migration to New Hosting
Changing hosting is a downtime risk. Proper process: set up a copy on new hosting, verify it works, only then switch DNS.
Migration Stages
1. Preparing the new server
# Installing LEMP stack on Ubuntu 22.04
sudo apt update && sudo apt upgrade -y
sudo apt install -y nginx mysql-server php8.2-fpm php8.2-mysql php8.2-gd \
php8.2-curl php8.2-zip php8.2-mbstring php8.2-xml php8.2-intl redis-server
# For Node.js projects
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt install -y nodejs
2. Copying files
# rsync preserving permissions and symlinks
rsync -avz --progress --exclude='.git' \
-e "ssh -p 22" \
user@old-server:/var/www/mysite/ \
user@new-server:/var/www/mysite/
# For large sites — via compressed archive
tar -czf /tmp/mysite.tar.gz -C /var/www mysite/
scp /tmp/mysite.tar.gz user@new-server:/tmp/
ssh user@new-server "tar -xzf /tmp/mysite.tar.gz -C /var/www/"
3. Database migration
# MySQL: dump and restore
mysqldump -u root -p mysite_db > /tmp/mysite_db.sql
scp /tmp/mysite_db.sql user@new-server:/tmp/
ssh user@new-server "mysql -u root -p new_db < /tmp/mysite_db.sql"
# PostgreSQL
pg_dump -U mysite mysite_db > /tmp/mysite_db.sql
scp /tmp/mysite_db.sql user@new-server:/tmp/
ssh user@new-server "psql -U mysite new_db < /tmp/mysite_db.sql"
4. Setup on new server
- Nginx/Apache virtual host
- Environment variables (.env)
- SSL certificate
- Directory permissions (storage, cache, uploads)
- Cron jobs
- Queue workers (if any)
5. Verification via hosts file (without DNS)
# On local machine add to /etc/hosts (or C:\Windows\System32\drivers\etc\hosts)
NEW_SERVER_IP mysite.com www.mysite.com
# Check site in browser via new server
# Verify everything works: forms, authentication, payments
6. DNS switch
Lower TTL to 300 seconds a day before switching. After switching TTL → normal value (3600+).
# Monitor propagation
watch -n 5 "dig @8.8.8.8 mysite.com A +short"
watch -n 5 "dig @1.1.1.1 mysite.com A +short"
Parallel Operation Period
Keep old server active 48–72 hours after DNS switch. This allows rollback if issues arise.
Checks After Migration
# Check availability
curl -I https://mysite.com
# Check SSL
echo | openssl s_client -connect mysite.com:443 2>/dev/null | grep "Verify return code"
# Check redirects
curl -I http://mysite.com # should be 301
curl -I http://www.mysite.com # should be 301
Standard website migration to new VPS — 4–16 hours depending on data volume.







