How to Migrate Your Website to a Cloud Server: Developer Guide

Copy files, export database, configure DNS, and test everything before the final switchover.
Before You Start: Essential Preparation
Moving a website to a new cloud server requires advance planning. Without proper preparation, you risk data loss or extended downtime. This guide covers migrating a PHP/Laravel site (or any web application) from one server to another, step by step.
Estimated execution time: 2-6 hours depending on site size and database.
Preparation Checklist
- Old server login credentials (SSH)
- New server login credentials (SSH)
- Old database credentials
- List of domains and subdomains
- Copy of current DNS settings
- List of connected services (APIs, mail services, external services)
- Complete backup before starting
Step 1: Prepare the New Server
Secure the Server
# Update system
apt update && apt upgrade -y
# Create new user
adduser deploy
usermod -aG sudo deploy
# Secure SSH
# In /etc/ssh/sshd_config:
Port 2222
PermitRootLogin no
PasswordAuthentication no
systemctl restart sshd
Install Required Software
# Nginx
apt install nginx -y
# PHP (example: PHP 8.3)
add-apt-repository ppa:ondrej/php -y
apt install php8.3-fpm php8.3-mysql php8.3-xml php8.3-mbstring php8.3-curl php8.3-zip php8.3-gd php8.3-bcmath -y
# MySQL/MariaDB
apt install mariadb-server -y
mysql_secure_installation
# Composer
curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer
# Node.js (if required)
curl -fsSL https://deb.nodesource.com/setup_20.x | bash -
apt install nodejs -y
# Certbot (SSL)
apt install certbot python3-certbot-nginx -y
Configure Firewall
ufw default deny incoming
ufw default allow outgoing
ufw allow 2222/tcp
ufw allow 80/tcp
ufw allow 443/tcp
ufw enable
Step 2: Transfer Files
Method 1: rsync (Recommended)
# From the new server, pull files from the old one
rsync -avz --progress -e "ssh -p 22" user@old-server:/var/www/mysite/ /var/www/mysite/
rsync transfers only the differences — if the connection drops, you can resume where it stopped.
Method 2: Compress and Transfer
# On the old server
cd /var/www
tar -czf mysite-backup.tar.gz mysite/
# Transfer to new server
scp -P 22 mysite-backup.tar.gz user@new-server:/var/www/
# On the new server
cd /var/www
tar -xzf mysite-backup.tar.gz
Set Permissions
chown -R www-data:www-data /var/www/mysite
chmod -R 755 /var/www/mysite
chmod -R 775 /var/www/mysite/storage
chmod -R 775 /var/www/mysite/bootstrap/cache
Step 3: Migrate the Database
Export from Old Server
mysqldump -u root -p --single-transaction --routines --triggers database_name > database_backup.sql
Important flags:
--single-transaction: Ensures data consistency without locking tables--routines: Includes stored procedures--triggers: Includes triggers
Import to New Server
# Create database and user
mysql -u root -p <<EOF
CREATE DATABASE database_name CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'app_user'@'localhost' IDENTIFIED BY 'strong_password_here';
GRANT ALL PRIVILEGES ON database_name.* TO 'app_user'@'localhost';
FLUSH PRIVILEGES;
EOF
# Import data
mysql -u root -p database_name < database_backup.sql
Verify
# Table count
mysql -u root -p -e "SELECT COUNT(*) FROM information_schema.tables WHERE table_schema='database_name';"
Compare the count with the old server — they must match.
Step 4: Configure the Application
Update Environment File (.env)
# Update database settings
DB_HOST=127.0.0.1
DB_DATABASE=database_name
DB_USERNAME=app_user
DB_PASSWORD=strong_password_here
# Update site URL
APP_URL=https://yourdomain.com
Run Laravel Commands
cd /var/www/mysite
composer install --no-dev --optimize-autoloader
php artisan config:cache
php artisan route:cache
php artisan view:cache
php artisan migrate --force
Configure Nginx
server {
listen 80;
server_name yourdomain.com www.yourdomain.com;
root /var/www/mysite/public;
index index.php;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
fastcgi_pass unix:/var/run/php/php8.3-fpm.sock;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.(?!well-known).* {
deny all;
}
}
ln -s /etc/nginx/sites-available/mysite /etc/nginx/sites-enabled/
nginx -t && systemctl reload nginx
Step 5: Switch DNS
Before Switching
# Lower TTL 24 hours before the switch
# Change TTL on all records to 300 seconds (5 minutes)
The Switch
# New DNS records
A @ NEW_SERVER_IP
A www NEW_SERVER_IP
After Switching
# Enable SSL
certbot --nginx -d yourdomain.com -d www.yourdomain.com
# Verify DNS
dig yourdomain.com +short
Step 6: Final Verification
| Check | Method |
|---|---|
| Site loads | Open the site in browser |
| SSL works | Verify the green lock |
| Database | Log in and verify data |
| Forms | Submit a test form |
| Send a test email | |
| API | Test all endpoints |
| Cron jobs | Verify crontab |
| Performance | Measure page load time |
Step 7: Post-Migration Monitoring
The first 48 hours are critical. Monitor:
- Error logs:
tail -f /var/log/nginx/error.log - System performance:
htop - Storage space:
df -h - Network traffic:
iftop
Migrate Your Site to CLOUD
CLOUD (cloud.net.sa) provides servers in Riyadh with very low latency latency. Your team handles the migration — and the CLOUD team offers free orientation sessions for your developers throughout the process. Server ready in 60 seconds with prices starting at competitive pricing — pricing and plans.
Get Started
Want to try it yourself? Choose the right hosting plan or build your custom server with the specs you need.
