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 to your computer. Alternatively you can take a backup from the WordPress backend and use this.
Step-2: Export Database
Export your database in SQL format using an application like phpMyAdmin.
- Select your database in phpMyAdmin.
- Click on Export.
- Select Custom in Export method
- Select Format as SQL
- If your database is big you might want to zip it. In this case select compression as zipped in Output section of export options.
- Click GO
Alternatively, you can take a database backup from cpanel and use it.
Step-3: Edit SQL script
Open the database export SQL file created from Step 2 in a text editor like textpad. If you zipped the file in step 2 then you have to unzip it first and then edit the contents. Do a search an replace, eg; search for abc.com and replace with xyz.com. When finished, zip it back 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.