How to migrate WordPress site

You will likely have to migrate a site from one hosting (server) to another or from one domain to another. The procedure is simple, but if you are migrating a site for the first time, take some time and concentration on this procedure. In this article, I will explain the easiest way to migrate a WordPress site.

This is the case where you have cPanel on your hosting, while the procedure is similar in each case.

First of all, it is recommended to make a backup copy of the site files and the database.

This is a complete manual on how to migrate the site to the other hosting or server.

Transfer Files


Copying site files to a new server

If you migrate the main domain of the cPanel account, the site files are located in the public_html directory. Copy all the files that are there and move them to the directory of the same name on the new hosting.

In case the domain you are migrating is not the main one on the account or you are not using cPanel, check in which directory the site files are located.


How to migrate the database and how to create the database

On the old hosting make a copy of the database, you can do it as follows:

  1. Open application phpMyAdmin
  2. Open site database
  3. Click on Export
  4. Click on the Go button to export database content and save the file.


Create a database on the new hosting

  1. Click on the application MySQL® Databases
  2. Into the field New Database enter the database name and click Create.

The name of the database can be the same as on the old hosting or a new one that you will later write in the site's wp-config.php file, which I will write about later in the text.


Create a user for the database

  1. Open MySQL® Databases application if you are not already at that step
  2. Find the section on the page named Add New User
    Be sure to write down the data that you will enter in the next steps, you will need it to enter in the wp-config.php file of your site.
  3. In the Username field, type the username you will use
  4. Enter the password in the Password and Password (Again) fields
  5. Click Create User to create a user for the database


Аssign the user to the database

  1. In the MySQL® Databases application, locate the Add User To Database page section
  2. In the User drop-down menu, select a user name, i.e. the user you created in the previous steps
  3. In the Database drop-down menu, select the name of the database you created in the previous steps
  4. Click Add and a new page will open
  5. Check ALL PRIVILEGES and click Make Changes

Congratulations, you have created a database, a user for the database and you have connected the user to the database.


Import the database

Now you need to import the database that you previously exported on the old hosting.

This can be done this way:

  1. Open phpMyAdmin
  2. Click on the database name you created in the previous steps
  3. Click on "Import"
  4. Choose file with the database data and click on "Go"


Setting up the wp-config.php file

If you have changed the name of the database or the password, set those data in the wp-config.php file, in any case you can check the data, especially if the site shows an error with the database.

The file location is public_html/wp-config.php

Open the specified file and check the following settings:

define( 'DB_NAME', 'here you enter the name of the database' );

define( 'DB_USER', 'here you enter the username you created in the previous steps' );

define( 'DB_PASSWORD', 'enter here the password for the username you created in the previous steps' );

define( 'DB_HOST', 'localhost' );

The DB_HOST setting should remain localhost, this means that we will use the database on the hosting where we are now, that is, we will not use another hosting for the database. As you can see, there is a possibility that the database is on another hosting, which I can write about another time.


Moving a WordPress site to another domain (site address)

This step is only necessary if you are moving the site to a new site address ie. a new domain. Ignore this step if you are not changing the site address.

In addition to the file and database migration described above, you need to set the site address in the wp-config.php file of WordPress.

Open the wp-config.php file and type the following:

define( 'WP_HOME', 'https://example.com' );
define( 'WP_SITEURL', 'https://example.com' );

Of course, instead of https://example.com, write the address of your site.


Having issues at a particular step during the migration? Feel free to contact me via the contact form on the website, describe the problem and step you are at and I will be very happy to answer and help.

Author: Aleksandar Vranešević
Published: 09-25-2022
Updated: 10-11-2022