🚀 How to Move a WordPress Website to a New Domain (Step-by-Step Guide)

Moving your WordPress site to a new domain may sound intimidating, but with the right steps, you can transfer all files, databases, and settings without losing data or SEO value.
This guide will walk you through preparing for the migration, moving files and databases, updating URLs, configuring HTTPS, and fixing common issues.


1️⃣ Preparation

Before making any changes, it’s important to prepare properly.

1. Create a Full Backup

  • Database – export via phpMyAdmin or the mysqldump command.
  • Site Files – download via FTP, SCP, or your hosting file manager.

2. Check Your Hosting Settings

  • Make sure the new domain is already connected to your hosting server.
  • Ensure you have SSH or FTP access to both the old and new servers.

2️⃣ Transferring WordPress Files

Step 1: Copy Your Website Files

scp -r /var/www/old_site_directory user@new_server_ip:/var/www/new_site_directory

Step 2: Set Correct Permissions

sudo chown -R www-data:www-data /var/www/new_site_directory/

3️⃣ Migrating the Database

Step 3: Export the Old Database

mysqldump -u username -p db_name > db_name.sql
scp db_name.sql user@new_server_ip:/path/to/directory

Step 4: Create and Import the Database on the New Server

mysql -u root -p
CREATE DATABASE db_name;
CREATE USER 'new_user'@'localhost' IDENTIFIED BY 'your-strong-password';
GRANT ALL PRIVILEGES ON db_name.* TO 'new_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;

mysql -u new_user -p db_name < db_name.sql

4️⃣ Updating URLs in the Database

When moving to a new domain, you need to replace all old domain references in your database.

  1. Download Search Replace DB.

  2. Upload and extract it into your site’s root directory.

  3. Open in a browser:

    http://new_domain/Search-Replace-DB-master
    
  4. Enter your DB credentials and replace old_domain.com with new_domain.com.

Option 2: Command-Line Search Replace

php srdb.cli.php -h localhost -n db_name -u db_user -p "db_pass" -s "old_domain.com" -r "new_domain.com"

Option 3: Manual Replace

  • Export your DB.
  • Open the SQL file in a text editor.
  • Use Find & Replace (Ctrl+H) to swap old URLs with the new ones.
  • Import the updated file back into the database.

5️⃣ Updating WordPress Configuration

  • wp-config.php – ensure no hardcoded URLs are set.
  • .htaccess – update redirects if needed.
  • Permalinks – in Settings → Permalinks, click Save Changes to refresh rewrite rules.

6️⃣ Enabling HTTPS on the New Domain

Use Certbot to set up a free SSL certificate:

sudo snap install --classic certbot
sudo ln -s /snap/bin/certbot /usr/bin/certbot
sudo certbot --nginx -d new_domain -d www.new_domain

Automate Certificate Renewal

crontab -e
0 0 15 * * sudo certbot renew --quiet

7️⃣ Fixing Common Problems

  • Mixed Content Warnings
    Add this to wp-config.php:

    if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')
        $_SERVER['HTTPS'] = 'on';
    
  • Broken Links / Missing Images
    Run another search-replace for any old URLs in posts or media.

  • SEO Redirects
    Set up a 301 redirect from the old domain to the new one via .htaccess or a plugin.


✅ Final Checklist

  • [ ] Backup created and stored safely.
  • [ ] Files and database transferred.
  • [ ] URLs updated in database.
  • [ ] HTTPS configured.
  • [ ] Internal links and images tested.
  • [ ] 301 redirects set up for SEO.

💡 Pro Tip: Always test your site on the new domain in a staging environment before making it live. This ensures minimal downtime and avoids surprises.

🚀 Explore more guides on our blog 👉 blog.1it.pro
📧 Contact us: admin@1it.pro for expert IT guidance.
🌐 Explore more: Visit 1it.pro for top-tier IT solutions.

UA EN RU

Зв'язатися з нами

Telegram Email