Moving Wordpress site while changing domain name

by Remy Pereira on 15th September 2017

Moving your Wordpress site can be as simple as moving the files and migrating the database as explained in my previous article Migrating Wordpress website. But most often you may also have to change the domain name and URLs. This is the case when you are migrating from a local development environment or from sub-domain to a live hosting account. This involves changing URLs in database tables and also in wp-config.php file. Here are the step-by-step instructions on how to do this:

Step-1: Download files

Download all the files in the Wordpress folder by FTP/SFTP to your computer. Alternatively you can do a cpanel backup or a wordpress backup from backend .

Step-2: Export Database

Export your database using a plugin such as WP Migrate DB. This plugin will replace all the databse entries corresponding to your old URL with the new URL. You may also take a backup from an application like phpMyAdmin or a cpanel database backup or a wordpress database backup. But these will be either SQL file or zipped SQL.

You may be tempted edit the SQL in a text editor to replace the URL using a normal search a replace. A word of caution! The database may contain serialized data (arrays and objects). A simple text replace breaks the serialization and may lead to unexpected results like broken plugins.WP Migrate DB unserializes the data into strings and then do a search and replace and finally serialize the data again.

Step-4: Create Database

Create the database in the new host, use the same name as the old database if possible. Some shared hosting providers automatically add a prefix to database names. In that case you have to change the database name in your wp-config.php (See Step-5).

You also need to create a database user and grant all privileges on your database to that user.

Step-5: Update wp-config.php file.

If the new database name, username or password is different from your old Wordpress site then you need to update them in the file wp-config.php

/** The name of the database for WordPress */
define( 'DB_NAME', 'new_database_name' );

/** MySQL database username */
define( 'DB_USER', 'new_username' );

/** MySQL database password */
define( 'DB_PASSWORD', 'new_password' );

Step-6: Upload files

Upload all Wordpress files in the home directory of the new hosting location (typically in public_html folder) by FTP.

Step-7: Test your site

Your site migration is now completed. You can now test your site to make sure it works correctly and all the links are accessible.

Post a comment


Nothing the first to share wisdom.