How to Migrate a WordPress Site to a New Domain

So you have just bought a new domain and plan to migrate your WordPress site from the old domain you have. One of the advantages of using a self-hosted WordPress is that you have a full control over your website, like this sort of case. You can migrate from a domain to another, with the precisely same contents and settings.

Migrating from a domain to another one is a bit challenging. It’s a different case to server migration. If you just want to migrate the server, there is nothing you need to change. You just need to copy all of the WordPress files from your old server to the new one as well as importing the database.

Different story applies when you want to migrate domain. You need to change the database content before you import it to the new server. Here is to migrate a WordPress site to a new domain.

Step 1: add a new domain on your new server

Before copying the WordPress files from your old server to the new one, you need to add a new domain on your new server. The method of adding a new domain can be different depending on the control panel you use. In may case, I use CentOS WebPanel on my VPS. In CentOS WebPanel, you can go to User Accounts -> New Account to add a new domain.

Step 2: Copy WordPress files from your old server and export the database

  • Copying files

Once you are done adding a new domain on your new server, return to your old server to copy all of the WordPress files (without exception, including the folders). The files you are going to copy are the ones under the root directory of your website. In most cases, the root directory is “public_html” or something similar. To ease your job in downloading the files later, you can create a new folder and copy the WordPress files on this new folder and archive it. This way, you will only need to download a single file (archive).

Since the size of the file you are going to download is big enough, especially if your site already have thousands or even hundred posts, I suggest you to use FTP to download it. FileZilla is a well-known FTP client app you can use.

  • Exporting database

Again, the method to export database can be different depending on the tool you use. I highly recommend you to use phpMyAdmin although there are several phyMyAdmin alternatives you can use as well.

Assuming that you use phpMyAdmin, select the database of your WordPress site and click the Export tab on the phpMyAdmin dashboard and click the Go button. Leave the format to SQL.

If you forgot the database name of your WordPress site, you can figure it out on the “wp-config.php” file.

Step 3: edit the content of the database

This is the most crucial step if you want to migrate a WordPress site domain. Before importing the database to your new server, you need to edit the content first.

The WordPress database stores plenty of information regarding your website, including the URLs. There are hundreds or thousands URLs stored on this database, depending on the content you have and editing them one by one can cause your hand to be curly. Actually, the part you need to edit is the domain name. For instance, if your old domain is “myblog.com” and your new domain is “yourblog.com”, all you need to do is replace “myblog.com” with “yourblog.com”.

The problem is that there are hundreds of lines containing the word of “myblog.com” and editing them one by one is no different than a craziness. To ease your job, you can use a text editor that has a find and replace feature. In this case, I use Gedit.

Step 4: Upload WordPress files to the new server and import the database

  • Uploading files

On the step 2 above, you have downloaded the WordPress files of your site. Now, it’s time to upload them to your new server. Again, I suggest you to use FTP to do so and FileZilla is an FTP client you can use to upload files to server. We have covered it in this port.

  • Importing database

Next, import the database that you have edited the content of on the step 3 above. But first, you need to create a new database on your new server. The method of creating a new database can be different depending on the control panel you use. On CentOS WebPanel, you can do so by going to SQL Services -> MySQL Manager and click the Create Database tab.

To start importing the database, login to phpMyAdmin and go to the Import tab and click the Choose File button. Click the Go button on the bottom. But first, make use you have selected the right database which you can check on the left panel of phpMyAdmin.

Step 5: edit the “wp-config.php” file

The next step you need to do is editing the “wp-config.php” file on your new server. There are four sections you need to edit: database name, database username, database password and database host.

Step 6: edit the name server

This is the final step. Once you are done with all steps above, the next step you need to do is editing the name server on your domain.

The method of editing name server can be different depending on the provider you bought the domain from. Just find the Nameservers menu or something similar on your domain manager and type your name servers on the available fields and click the Update Nameservers button.

It takes commonly about 24-48 hours of propagation before your new domain can be accessed. Just be patient and keep calm until the propagation is complete.

Related posts

Written by Al Putra

An open source user, Manchester United fan and CC0-licensed stuffs lover



Leave a Comment

Your email address will not be published. Required fields are marked *