Knowledge Base

How to migrate an existing WordPress site to A2 Hosting

This article describes how to migrate an existing WordPress site to an A2 Hosting account.

This article describes how to migrate a WordPress site manually. There are also plugins that can help you migrate an existing WordPress site, such as Duplicator and WordPress Move, but A2 Hosting does not provide support for these plugins, and they may not work for all configurations.

Migrating an existing WordPress site to A2 Hosting

If you already have a WordPress site with another hosting provider and want to move the site to A2 Hosting, you do not need to install WordPress and start all over. Instead, you can migrate the WordPress site to your A2 Hosting account. To ensure the migrated site works correctly, there are five main things to do:

  • Migrate the WordPress files, including all application code files, plugins, themes, and configuration files.
  • Migrate the WordPress MySQL database.
  • Configure any custom settings that are in php.ini or .htaccess files.
  • Configure domain settings.
  • Test the new site.

The following sections guide you through each of these steps.

Step 1: Migrate the WordPress files

The first step is to migrate all of the WordPress files from the existing site to your A2 Hosting account. The easiest way to do this is compress all of the files into a single .zip file that contains the WordPress core application files, configuration files, plugins, and themes.

Using cPanel

If your hosting accounts include cPanel, you can use the File Manager to migrate the WordPress files. To do this, follow these steps:

  1. To compress the WordPress files into a .zip file:
    • Log in to cPanel on the account that hosts the existing WordPress site.
    • In the Files section of the cPanel home screen, click File Manager.
    • In the Directory Selection dialog box, select Home Directory, confirm that the Show Hidden Files check box is selected, and then click Go.
    • In the File Manager's main pane, right-click the public_html directory, and then click Compress.
      If WordPress is not installed in the public_html directory, go to the directory that contains the WordPress files instead.
    • In the Compress dialog box, select Zip Archive, and then click Compress File(s).
    • After the File Manager finishes compressing the directory into the public_html.zip file, click Close.
  2. Use the cPanel File Manager or FTP to upload the public_html.zip file to the home directory on your A2 Hosting account.
  3. To extract the WordPress files from the public_html.zip file:

    • Log in to cPanel on your A2 Hosting account.
    • In the Files section of the cPanel home screen, click File Manager.
    • In the Directory Selection dialog box, select Home Directory, confirm that the Show Hidden Files check box is selected, and then click Go.
    • In the File Manager's main pane, right-click the public_html.zip file, and then click Extract.
    • In the Extract dialog box, click Extract File(s).
    • After the File Manager finishes extracting the files, click Close.
  4. The core WordPress files are now in the public_html directory. The next step is to migrate the WordPress database. Please see step 2 below.
Using the command line

If your hosting accounts do not include cPanel, you can use the command line interface to migrate the WordPress files instead. To do this, follow these steps:

  1. Use SSH to log in to the account that hosts the existing WordPress site, and then type the following commands:
    cd ~
    zip -r public_html.zip public_html
    These commands assume that WordPress is installed in the public_html directory. If WordPress is installed in a different directory, use that directory in the zip command instead.
  2. Use FTP to upload the public_html.zip file to the home directory on your A2 Hosting account.
  3. To extract the files from the public_html.zip file, log in to your A2 Hosting account using SSH, and then type the following commands:

    cd ~
    unzip public_html.zip
    These commands assume that WordPress will be configured in the public_html directory. If you used another directory in step 1 to create the .zip file, use that directory instead.
  4. The core WordPress files are now in the public_html directory. The next step is to migrate the WordPress database. Please see step 2 below.
Step 2: Migrate the WordPress MySQL database

After you migrate the WordPress files, you are ready to migrate the WordPress MySQL database.

Using cPanel

If your hosting accounts include cPanel, you can use phpMyAdmin to migrate the MySQL database. To do this, follow these steps:

  1. On the existing WordPress site, make sure you have the correct name of the WordPress database. To do this, open the wp-config.php file in a text editor, and look for the line that starts with define('DB_NAME'. This setting defines the MySQL database that WordPress uses.
  2. To export the MySQL database:
    • Log in to cPanel on the account that hosts the existing WordPress site.
    • In the Databases section of the cPanel home screen, click phpMyAdmin.
    • In the left pane of phpMyAdmin, click the name of the database that you obtained from the wp-config.php file in step 1.
    • On the top menu bar, click Export.
    • Under Export Method select Quick, in the Format list box select SQL, and then click Go.
    • In the Save File dialog box, type wordpress.sql for the filename, and then save the file on your local computer.
  3. Use the cPanel File Manager or FTP to upload the wordpress.sql file to the home directory on your A2 Hosting account.
  4. To create a new MySQL database for the migrated WordPress site:

    • Log in to cPanel on your A2 Hosting account.
    • In the Databases section of the cPanel home screen, click MySQL Databases.
    • Under Create New Database, type a name for the new database in the New Database text box, and then click Create Database.
    • Click Go Back.
    • Under Add User To Database, select a user in the User list box, and then in the Database list box, select the name of the database you created.
    • Click Add.
  5. To import the MySQL data into the new database:

    • Log in to cPanel on your A2 Hosting account.
    • In the Databases section of the cPanel home screen, click phpMyAdmin.
    • In the left pane of phpMyAdmin, click the name of the database that you created in step 4.
    • On the top menu bar, click Import.
    • Under File to Import, click Browse.
    • Select the wordpress.sql file that you uploaded in step 3, and then click Open.
    • Click Go. phpMyAdmin imports the data into the database.
  6. Open the public_html/wp-config.php file in a text editor, and then update the following settings:

    define('DB_NAME', 'database_name');
    define('DB_USER', 'database_user');
    define('DB_PASSWORD', 'database_password');

    Replace database_name with the name of the new database, database_user with the database username, and database_password with the database user's password.

  7. The database is now ready for WordPress to use. The next step is to configure custom settings. Please see step 3 below.
Using the command line

If your hosting accounts do not include cPanel, you can use the command line interface to migrate the MySQL database. To do this, follow these steps:

  1. On the existing WordPress site, make sure you have the correct name of the WordPress database. To do this, open the wp-config.php file in a text editor, and look for the line that starts with define('DB_NAME'. This setting defines the MySQL database that WordPress uses.
  2. To export the MySQL database, use SSH to log in to the account that hosts the existing WordPress site, and then type the following command. Replace USERNAME with your account username, and replace DBNAME with the name of the WordPress database that you obtained from the wp-config.php file in step 1:
    mysqldump -u USERNAME -p DBNAME > wordpress.sql
    
  3. Use FTP to upload the wordpress.sql file to the home directory on your A2 Hosting account.
  4. To create a new MySQL database for the new WordPress site, log in to your A2 Hosting account using SSH, and then type the following command. Replace USERNAME with the MySQL username, and replace NEW_DBNAME with the name of the new WordPress database that you want to create:

    mysql -u USERNAME -p -e "CREATE DATABASE NEW_DBNAME"
    
  5. To import the MySQL data into the new database, type the following command. Replace USERNAME with the MySQL username, and replace NEW_DBNAME with the name of the MySQL database that you created in step 4:

    mysql -u USERNAME -p NEW_DBNAME < wordpress.sql
    
  6. Open the public_html/wp-config.php file in a text editor, and then update the following settings:

    define('DB_NAME', 'database_name');
    define('DB_USER', 'database_user');
    define('DB_PASSWORD', 'database_password');

    Replace database_name with the name of the new database you created in step 4, database_user with the database username, and database_password with the database user's password.

  7. The database is now ready for WordPress to use. The next step is to configure custom settings. Please see step 3 below.
Step 3: Configure custom settings

You may have custom settings for your WordPress site in one or both of the following files:

  • php.ini
  • .htaccess

If you have either of these files on your account that hosts the existing site, review them to determine if you need to migrate any of the settings to your A2 Hosting account. If you do, you can either copy the entire file or files, or selectively add settings.

Step 4: Configure domain settings

The next step is to configure your domain settings. The steps required depend on your migration scenario:

  • If you are migrating from another hosting provider to A2 Hosting and want to use the same domain name, you must configure the domain's name server settings to point to the A2 Hosting server that hosts your account. You do not need to change any domain settings in WordPress.
    For information about how to set a domain's name servers to point to A2 Hosting, please see this article.
  • If you are migrating from another hosting provider to A2 Hosting and want to use a different domain name, you must configure the domain's name server settings to point to the A2 Hosting server that hosts your account.
    For information about how to set a domain's name servers to point to A2 Hosting, please see this article.

    Additionally, you must manually update the WordPress database to use the new domain name. To do this, follow these steps if your hosting account includes cPanel:

    1. Log in to cPanel on your A2 Hosting account.
    2. In the Databases section of the cPanel home screen, click phpMyAdmin.
    3. In the left-hand pane of phpMyAdmin, click the name of the WordPress database. A list of tables in the database appears.
    4. Under the Table heading, click the wp_options table. A list of data rows appears.
    5. Under the option_name heading, locate siteurl, and then click Edit.
    6. In the option_value text box, replace the current URL with the new domain name that you want to use.
      • Make sure you type the correct URL for the domain name, or your WordPress site will be inaccessible.
      • Make sure the URL begins with http://.
      • Make sure the URL does not end with a forward slash (/).
    7. Click Go. phpMyAdmin saves the changes in the table.
    8. Under the option_name heading, locate home, and then click Edit.

      You may have to scroll through more than one page of data in the wp_options table to locate the home row. To do this, click the > icon, or you can click Show all to view all of the table's rows at once.
    9. In the option_value text box, replace the current URL with the new domain name that you want to use.

      • As above, make sure you type the correct URL, or your WordPress site will be inaccessible.
      • Make sure the URL begins with http://.
      • Make sure the URL does not end with a forward slash (/).
    10. Click Go. phpMyAdmin saves the changes in the table. The migrated WordPress site should now function correctly using the new domain name.

    Alternatively, if your hosting account does not include cPanel, use the command line interface to update the WordPress database with the correct domain name. To do this, follow these steps:

    1. Log in to your A2 Hosting account using SSH, and then type the following commands. Replace USERNAME with the MySQL username, replace NEW_DBNAME with the name of the MySQL database, and replace example.com with the new domain name that you want to use:
      mysql -u USERNAME -p NEW_DBNAME -e "UPDATE wp_options SET option_value = 'http://www.example.com' WHERE option_name = 'siteurl';"
      mysql -u USERNAME -p NEW_DBNAME -e "UPDATE wp_options SET option_value = 'http://www.example.com' WHERE option_name = 'home';"
      
      If you migrated WordPress to a subdirectory, include it in the URL as well. For example, if you migrated WordPress to the public_html/wordpress directory, the URL would be http://www.example.com/wordpress, where example.com represents your domain name.
    2. To verify that the new domain settings are in the WordPress database, type the following commands. Replace USERNAME with the MySQL username, and replace NEW_DBNAME with the name of the MySQL database:

      mysql -u USERNAME -p NEW_DBNAME -e "SELECT * FROM wp_options WHERE option_name = 'siteurl';"
      mysql -u USERNAME -p NEW_DBNAME -e "SELECT * FROM wp_options WHERE option_name = 'home';"
      
Step 5: Test the new site

Lastly, you should test the newly migrated WordPress site on your A2 Hosting account to ensure that it works. Specifically, at a minimum you should test the following:

  • Make sure the site appears at http://www.example.com, where example.com represents your domain name.
  • Make sure posts and other pages appear correctly.
  • Make sure you can log in as the administrator. If you need to reset the WordPress administrator password, please see this article.

After you complete the migration, you may want to consider adding the following features to your WordPress site to help improve performance and security:

  • CAPTCHA protection can help protect your site from spamming by bots and other malicious actors. For information about how to set up CAPTCHA protection for your WordPress site, please see this article.
  • Caching can dramatically improve your WordPress site's performance. For information about how to configure caching, please see this article.
  • The A2 Optimized for WordPress plugin combines custom A2 Hosting settings and functionality from third-party plugins to help accelerate and secure your WordPress site. For information about how to install the A2 Optimized for WordPress plugin, please see this article.