How to Change Your Domain Name on EC2 Without Reinstalling Your CMS: Complete Migration Guide
Learn how to seamlessly migrate your domain on EC2 servers without reinstalling your CMS. Includes configuration updates, social media connections, and mail server setup.
Super Admin
Author
Introduction: Why Domain Changes Don't Require Fresh Installs
Changing your domain name on an EC2 server might seem daunting, but you don't need to reinstall your entire CMS. Whether you're rebranding, moving to a more professional domain, or consolidating multiple sites, this comprehensive guide will walk you through every step of the domain migration process while preserving your existing setup, data, and configurations.
This tutorial covers everything from server configuration updates to social media reconnections and mail server adjustments, ensuring zero downtime and complete functionality after your domain change.
Prerequisites and Preparation
Before starting your domain migration, ensure you have the following:
- SSH access to your EC2 instance
- Root or sudo privileges on the server
- Database backup (always backup before major changes)
- DNS management access for both old and new domains
- SSL certificate for the new domain
- List of all integrated services (social media, email, APIs)
Step 1: Update Web Server Configuration
Apache Configuration Updates
If you're running Apache, locate your virtual host configuration file, typically found in /etc/apache2/sites-available/:
Important: Always create a backup of your configuration files before making changes. Run
sudo cp /etc/apache2/sites-available/your-site.conf /etc/apache2/sites-available/your-site.conf.backup
Edit your virtual host file and update the ServerName and ServerAlias directives:
<VirtualHost *:80>
ServerName yournewdomain.com
ServerAlias www.yournewdomain.com
DocumentRoot /var/www/html
# ... rest of your configuration
</VirtualHost>
Nginx Configuration Updates
For Nginx servers, edit your site configuration in /etc/nginx/sites-available/:
server {
listen 80;
server_name yournewdomain.com www.yournewdomain.com;
root /var/www/html;
# ... rest of your configuration
}
After updating configurations, test and restart your web server:
sudo apache2ctl configtest # For Apache
sudo nginx -t # For Nginx
sudo systemctl restart apache2 # For Apache
sudo systemctl restart nginx # For Nginx
Step 2: Update CMS Configuration Files
WordPress Configuration
For WordPress installations, update the wp-config.php file and database entries:
// In wp-config.php
define('WP_HOME','https://yournewdomain.com');
define('WP_SITEURL','https://yournewdomain.com');
// Database updates via WP-CLI or MySQL
wp search-replace 'https://olddomain.com' 'https://yournewdomain.com' --dry-run
wp search-replace 'https://olddomain.com' 'https://yournewdomain.com'
Laravel Configuration
For Laravel applications, update your .env file:
APP_URL=https://yournewdomain.com
APP_DOMAIN=yournewdomain.com
# Update any other domain-specific variables
MAIL_FROM_ADDRESS=noreply@yournewdomain.com
SESSION_DOMAIN=.yournewdomain.com
Clear and rebuild caches:
php artisan config:clear
php artisan cache:clear
php artisan config:cache
Generic CMS Configurations
For other CMS platforms, look for configuration files containing domain references:
- Database connection strings
- Base URL settings
- Cookie domain configurations
- API endpoint URLs
- Asset URLs and CDN configurations
Step 3: SSL Certificate Setup
Secure your new domain with SSL certificates. Using Let's Encrypt with Certbot:
sudo certbot --apache -d yournewdomain.com -d www.yournewdomain.com # For Apache
sudo certbot --nginx -d yournewdomain.com -d www.yournewdomain.com # For Nginx
Verify your SSL configuration and set up automatic renewal:
sudo certbot renew --dry-run
Step 4: DNS Configuration Updates
A Records and CNAMEs
Update your DNS settings to point to your EC2 instance:
- A Record: yournewdomain.com → Your EC2 Elastic IP
- CNAME Record: www.yournewdomain.com → yournewdomain.com
- CNAME Record: *.yournewdomain.com → yournewdomain.com (if using subdomains)
TTL Considerations
Set low TTL values (300 seconds) during migration to allow quick DNS propagation, then increase to standard values (3600 seconds) after successful migration.
Step 5: Mail Server and MX Record Updates
MX Record Configuration
Update your MX records to point to your mail server:
- Priority 10: mail.yournewdomain.com
- Priority 20: backup-mail.yournewdomain.com (if applicable)
Postfix Configuration Updates
If running Postfix, update /etc/postfix/main.cf:
myhostname = mail.yournewdomain.com
mydomain = yournewdomain.com
myorigin = $mydomain
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
Restart Postfix after changes:
sudo systemctl restart postfix
SPF and DKIM Records
Update your DNS with proper mail authentication records:
- SPF Record: "v=spf1 a mx ip4:YOUR-EC2-IP ~all"
- DKIM Record: Update with your domain key selector
- DMARC Record: "v=DMARC1; p=quarantine; rua=mailto:dmarc@yournewdomain.com"
Step 6: Social Media Platform Updates
Facebook Integration
Update your Facebook App settings:
- Navigate to Facebook Developers Console
- Select your app and go to Settings → Basic
- Update App Domains to include your new domain
- Update Privacy Policy URL and Terms of Service URL
- In Facebook Login settings, update Valid OAuth Redirect URIs
Google Services Integration
For Google OAuth and APIs:
- Access Google Cloud Console
- Navigate to APIs & Services → Credentials
- Edit OAuth 2.0 Client IDs
- Update Authorized JavaScript origins and redirect URIs
- Update Google Analytics and Search Console properties
Twitter API Updates
Update Twitter Developer Portal:
- Access Twitter Developer Portal
- Navigate to your app settings
- Update Website URL and Callback URLs
- Update Terms of Service and Privacy Policy links
Instagram Business Integration
For Instagram Business API:
- Update Facebook App settings (Instagram uses Facebook's platform)
- Verify domain ownership in Facebook Business Manager
- Update webhook URLs if using Instagram webhooks
Step 7: Additional Service Integrations
Payment Gateway Updates
Update payment processor settings:
- Stripe: Update webhook endpoints and domain whitelist
- PayPal: Update return URLs and webhook notifications
- Square: Update application URLs and webhook endpoints
CDN Configuration
If using CloudFlare or AWS CloudFront:
- Add new domain to CDN configuration
- Update SSL certificates
- Configure cache purging rules
- Update CNAME records to point to CDN
Email Service Providers
Update email service configurations:
- SendGrid: Update sender authentication and domain verification
- Mailgun: Add new domain and configure DNS records
- Amazon SES: Verify new domain and update sending policies
Step 8: Testing and Validation
Functionality Testing
Perform comprehensive testing:
- Test website loading and all pages
- Verify SSL certificate installation
- Test contact forms and email delivery
- Validate social media login functionality
- Test payment processing (in sandbox mode)
- Check mobile responsiveness
DNS Propagation Check
Use tools to verify DNS propagation:
- whatsmydns.net
- dnschecker.org
- Command line:
nslookup yournewdomain.com
Step 9: SEO and Analytics Migration
Google Analytics Update
Update Google Analytics property settings:
- Navigate to Admin → Property Settings
- Update Default URL to new domain
- Set up 301 redirects from old domain
- Update goal URLs and filters
Search Console Migration
Add new domain to Google Search Console:
- Add new property for new domain
- Verify ownership via DNS or HTML file
- Submit new sitemap
- Set up Change of Address tool if applicable
Step 10: Monitoring and Maintenance
Set Up Monitoring
Configure monitoring for your new domain:
- SSL certificate expiration alerts
- Website uptime monitoring
- DNS resolution monitoring
- Email deliverability monitoring
Log File Updates
Update log rotation and monitoring scripts:
# Update logrotate configurations
sudo nano /etc/logrotate.d/apache2 # or nginx
# Update any custom log parsing scripts
# Update monitoring dashboard configurations
Troubleshooting Common Issues
SSL Certificate Issues
If experiencing SSL problems:
- Verify certificate installation with SSL checker tools
- Check for mixed content warnings
- Ensure all internal links use HTTPS
- Update .htaccess for automatic HTTPS redirects
Email Delivery Problems
Common email issues and solutions:
- Check SPF, DKIM, and DMARC records
- Verify MX record propagation
- Test with mail-tester.com
- Check server firewall settings for port 25, 587, 465
Social Media Integration Failures
If social logins fail:
- Clear browser cache and cookies
- Verify all redirect URLs are updated
- Check app permissions and scopes
- Ensure domain verification is complete
Post-Migration Checklist
Complete this checklist after your domain migration:
- ✅ Website loads correctly on new domain
- ✅ SSL certificate is properly installed
- ✅ All forms and contact methods work
- ✅ Social media logins function properly
- ✅ Email sending and receiving work
- ✅ Payment processing is functional
- ✅ Analytics tracking is updated
- ✅ SEO redirects are in place
- ✅ All third-party integrations work
- ✅ Mobile version displays correctly
Conclusion
Successfully migrating your domain on EC2 without reinstalling your CMS requires careful planning and systematic execution. By following this comprehensive guide, you've updated your server configurations, maintained all social media connections, configured proper mail settings, and ensured seamless functionality across all integrated services.
Remember to monitor your new domain for the first few days after migration to catch any issues early. Keep your old domain active with proper 301 redirects for at least 6 months to maintain SEO value and ensure users can still find your site during the transition period.
With proper preparation and execution, your domain migration should be invisible to your users while providing you with the professional web presence your business deserves.
Tags
Written by
Super Admin
Author at ZartonAi
Comments (0)
No comments yet. Be the first to share your thoughts!
Protected by reCAPTCHA. Privacy & Terms.