Software Developer

Manual Steps To Migrate a WordPress Site To Another Hosting Account

These are easy and complete steps to migrate a WordPress site from one hosting account to another (i.e. from one server to another). This method keeps your entire WordPress site intact through the move. The purpose here is to document the complete manual steps for migrating a WordPress site, so this does it without the help of any plugins, and without the help of any hosting-specific backup services.

This has worked for me countless times, and nothing has broken during the migration. (Disclaimer: Follow my steps at your own risk.)

Things You’ll Need

Two things are necessary in order to follow my steps:

  1. Both hosting accounts are Linux hosting accounts (the hosting account you are migrating from, and the hosting account your are migrating to).
  2. You are on a computer that can make an SSH connection to your hosting account. (on Windows, you can use an SSH client such as PuTTY). This also means that SSH connections must be enabled on your hosting account. Check your hosting account panel to enable SSH connections.

Steps To Migrate Your WordPress Site

  1. Export a copy of your existing WordPress database. To do this, you can log in to your old hosting account (the account that you want to migrate FROM), look for the PHPMyAdmin link and click on it. Then, from PHPMyAdmin, click on the name of your WordPress database on somewhere in the left column. Then, click the “Export” tab on the menu across the top of the page. From there, you will be able to export (download) a copy of your .sql database.
  2. Next, log in to your NEW hosting account (the account which you are moving TO). Create a new database. Write down the new database name, database user’s username, database user’s password, and the database host. Once the new database is created, go into PHPMyAdmin and click its name on the left column. Click on the “Import” tab on the top menu. From there, you can import your database which you exported in the previous step. It’s usually best to UNCHECK the “Partial Import” option when importing your database file unless you have something like 10,000+ posts.
  3. Now, open a terminal. Make an SSH connection to the old hosting account (the account that you want to move FROM). Navigate to the root directory of your site. This is the folder that holds all of the files for your site. This is usually a folder named public_html or something similar.

    If you are hosting multiple sites on your hosting account, and you only want to migrate one of the sites, the site that you want to migrate may be in another folder. For example, it may be in a nested folder: public_html/addon_site.com/. In this case, navigate into the addon_site.com folder.

    To navigate to the public_html folder, use:

    cd public_html

    Or, to navigate to a folder for an add-on site, use:

    cd public_html/addon_site.com
  4. Use tar to package the site which you want to migrate:

    (You may change ‘mysite_backup’ to the name of your own site.)

    tar -cvzf mysite_backup.tar.gz .
    If you have multiple websites on this hosting account, but you only want to migrate the main site, and not the addon sites, then you would want to exclude the addon site directories from this package. This is assuming that the folders for the addon sites are sitting in this root directory of your main site. So, instead of the line above, use the following one. To exclude the addon sites from the tar package, you would add an exclude argument for each addon site folder. For example, this would exclude “addon_site.com” and “another_addon_site.com”:

    tar -cvzf astro2016-02.tar.gz --exclude=addon_site.com --exclude=another_addon_site.com .
  5. Make sure your package was created:

    ls -lah *.tar.gz

    If you see it listed, then it was created.

  6. Close the SSH connection:

    exit
  7. Make an SSH connection to the new hosting account (the account that you want to copy files TO). Navigate to the directory in which the site files belong. This will usually be the public_html directory, unless you have a hosting account that let’s you host multiple web sites (In this case, move to the subfolder for the particular site which you are moving).
  8. Import the packaged file from the source site. The source site is the site that you were just connected to via SSH in step 3. First, in the following command, change “sourcesite.com” to your actual site.

    If your source site is an “addon” site, for example, if in step 3 you moved into a folder for an addon site, then you must change sourcesite.com to sourcesite.com/addon_site.com.

    Change “mysite_backup.tar.gz” to the name of your package which you created in step 4. (Change “mysite_backup” every time you see it in the next couple steps, to the name of the package you created in step 4.)

    For a regular site:

    wget http://sourcesite.com/mysite_backup.tar.gz

    For an addon site:

    wget http://sourcesite.com/addon_site.com/mysite_backup.tar.gz
  9. Extract the package:

    tar -xvzf mysite_backup.tar.gz
  10. Delete the ‘.tar.gz’ file which we no longer need.

    rm -f mysite_backup.tar.gz
  11. Update wp-config.php with new database details. To do this, open the wp-config.php file in the VI editor:

    vi wp-config.php
  12. Update the 4 database details to those of new database. You simply have to paste the 4 four pieces of information which you wrote down above when you created the new database. These are:

    Database Name
    Database Username
    Database User Password
    Database Host

    Those 4 bits of information go into the first 4 lines, respectively, of wp-config.php (ignoring comments). On the command line, you’ll type “i” to insert. Then use your arrow keys to move the cursor to where you want to type the new information.

    For example, the first line of code (ignoring comments) looks like this:

    define('DB_NAME', 'database_name_here');

    So, change ‘database_name_here‘ into your own database name. Make the 4 changes with the 4 bits of information that I listed above. You can either type your text into the VI editor, or you can also paste text into the VI editor.

  13. Save your changes to wp-config.php in the VI editor. To do this, first press the escape key on your keyboard (“Esc“). Next, on the command line, enter:

    :wq
  14. Exit:

    exit
  15. Now that the entire WordPress site, including files and the WP database, are at the new hosting account, you can point your domain to the new hosting account. Your domain registrar (where you have your domain name registered) will have the steps for you to do this. If you have your domain registered with the same company of your hosting account, this should be pretty easy. It will probably involve unlinking your domain name from the old hosting account, waiting a few minutes for this to process, and then linking the domain name to your new hosting account. Since your WordPress website’s files and database are already at the new hosting account, your site’s downtime during the domain transfer will be minimal. Once your registrar points your domain to the new hosting account, your WordPress website will be up and running just as before. The migration is then complete. At that point, you can delete your site’s files and database from the old hosting account since they are no longer being used.

By

Questions and Comments are Welcome

Your email address will not be published. All comments will be moderated.

Please wrap code in "code" bracket tags like this:

[code]

YOUR CODE HERE 

[/code]