Changing the domain of a WordPress website involves more than just purchasing a new domain name; it requires migrating the entire website—including files and the database—while ensuring that all links and configurations point to the new domain. Without proper migration, broken links, database mismatches, and login issues can occur, leading to a non-functional site. This guide walks through the step-by-step process of backing up and reinstating WordPress, correctly uploading the files to the new domain, updating database references, and fixing any warnings or errors to ensure a smooth transition.

Backing up and reinstating WordPress

Basic steps to follow:

  • Connect to your site using FTP.
  • Download all your site’s files to your local computer.
  • Access your site’s database using phpMyAdmin.
  • Export your site’s database and download a copy to your local computer.

Step 1:

To begin the process, you need to connect to your server using FTP and an FTP client like FileZilla. You can get your FTP credentials from your hosting dashboard.

Step 2:

Once you’re connected to your server, browse to the folder that contains your WordPress site’s files. Download all the files and folders to your local computer to save a full copy of your site’s files.

Step 3:

While you’ve successfully backed up your site’s files, all your WordPress content is stored in your site’s database. So, to take a complete WordPress manual backup, you also need to save a copy of your site’s database.

To start, log in to your hosting dashboard and access the phpMyAdmin tool. How you access phpMyAdmin will depend on your host.

  • Select your site’s database in phpMyAdmin (if multiple exist).

Step 4:

Go to the Export tab on the top menu bar. Select Quick as the export method and SQL as the format. Then, click Export to download a copy of the database to your local computer.

Now that you have downloaded both your site’s files and database, you have a complete backup of your WordPress site.

Uploading the Files on a New Domain

Uploading the current files will work best on a fresh installation of WordPress. (This is to make sure you have a working database for the site on the new domain)

  • Make a new installation of WordPress on the new domain.
  • Connect to your site using FTP.
  • Replace the existing WordPress files with your backup files.
  • Import the SQL Database through the SQL file using phpMyAdmin.

Step 1:

Make a new installation of WordPress on the new domain. (This will create a wp-config.php file that contains the connection credentials for the database.)

Step 2:

Connect to your server using FTP and an FTP client, just like you did for backing up the files.

Step 3:

Navigate to the folder that contains the wp-config.php file from the new WordPress installation and download it. Take a screenshot of the MySQL settings section from the code (we will use the screenshot later to correctly edit the wp-config.php file from our backed-up files).

Step 4:

Navigate to the folder that contains the WordPress site’s files and replace the existing files with the files from the backup.

Note: The upload button wasn’t working since I wasn’t connected to a server.

On a new WordPress installation, you will be prompted to replace or skip over matching files. You will need to replace the files.

Step 5:

Before we import the backed-up data into the new database, we need to make sure we will import it into the correct database. For this, we need to:

  • Open the new database (the one created with the new WordPress installation) in phpMyAdmin.
  • Verify and copy the name of the database.
  • Open the exported file and look for the row where the database is created (this should be rows 24 and 25).

Make sure to comment out the row where the database is created if it doesn’t exist and write the name of your new database in the USE ‘dbs***’ row.

Step 6:

Using phpMyAdmin, access the structure of the new database, select all the tables in the database, and drop them. (They will be replaced by our old tables.)

Now open the import tab and import the SQL file that was exported from the old database.

Step 7:

To make sure that the WordPress Website is connected to the new database, open the site’s wp-config.php file and configure: DB_NAME, DB_USER, DB_PASSWORD, and DB_HOST to match the current database.

(This is where we use the screenshot from Step 3.)

Step 8:

Match the links in the database by copying the following SQL statement in phpMyAdmin inside the imported database, replacing the placeholder links with actual links.


-- Update the Site URL and Home URL in the wp_options table
UPDATE wp_options 
SET option_value = REPLACE(option_value, 'https://www.oldurl.com', 'https://www.newurl.com') 
WHERE option_name = 'home' OR option_name = 'siteurl';

-- Update URLs in the wp_posts table (guid)
UPDATE wp_posts 
SET guid = REPLACE(guid, 'https://www.oldurl.com', 'https://www.newurl.com');

-- Update URLs in the wp_posts table (post_content)
UPDATE wp_posts 
SET post_content = REPLACE(post_content, 'https://www.oldurl.com', 'https://www.newurl.com');

-- Update URLs in the wp_postmeta table
UPDATE wp_postmeta 
SET meta_value = REPLACE(meta_value, 'https://www.oldurl.com', 'https://www.newurl.com');

-- Update URLs in the wp_usermeta table
UPDATE wp_usermeta 
SET meta_value = REPLACE(meta_value, 'https://www.oldurl.com', 'https://www.newurl.com');

-- Update URLs in the wp_links table (if used)
UPDATE wp_links 
SET link_url = REPLACE(link_url, 'https://www.oldurl.com', 'https://www.newurl.com');

-- Update URLs in the wp_comments table (if URLs are present in comments)
UPDATE wp_comments 
SET comment_content = REPLACE(comment_content, 'https://www.oldurl.com', 'https://www.newurl.com');

-- Update URLs in the wp_commentmeta table (if URLs are present in comment metadata)
UPDATE wp_commentmeta 
SET meta_value = REPLACE(meta_value, 'https://www.oldurl.com', 'https://www.newurl.com');
    

How to Remove Warnings Displayed on the Site

Quick-fix in wp-config.php: (Note: it’s just a way to hide those warnings and notices by disabling error reporting in the wp-config file)


ini_set('display_errors','Off'); 
ini_set('error_reporting', E_ALL ); 
define('WP_DEBUG', false);
define('WP_DEBUG_DISPLAY', false);