Manually migrate WordPress to DreamHost

 

Overview

This article describes how to migrate your WordPress site from your current host to DreamHost. These instructions can be used for any type WordPress and DreamPress website as well as migrating to a different domain name.

If you are having trouble migrating your website from another host or just don't have the time, DreamHost offers a service that takes care of that for you. View the Website migration services article for more information.

For additional Automated and Professional migration options, view Migrating WordPress overview article.

Back up your website at your current host

Before making any changes to your website, DreamHost highly recommends backing up both your website files and your database at your current hosting company.

Website files

Contact your current host for instructions on how to export your website files. They should have instructions on how to log into your server via FTP to download your files and save them to a .zip file.

In the steps below, you only need to upload the wp-content folder.

Uploading your .htaccess and wp-config.php files is only necessary if you have custom coding within these files.

Database file

Contact your current host for instructions on how to export your website's database. You will need to download a file ending with a .sql extension.

Install WordPress

Make sure your domain is fully hosted in your DreamHost panel and that WordPress is already installed.

DreamHost recommends using the DreamHost WordPress installer or purchasing a DreamPress plan to have the WordPress core files installed automatically.

 

Step 1 — Clear out your DreamHost database

When you installed WordPress in the panel, a database was created automatically for you. You must now clear out all tables in this database so it is blank. You can then import your SQL file into it.

phpMyAdmin

View the following articles for instructions on how to log into your database via phpMyAdmin:

You can also obtain your database credentials by opening your wp-config.php file. You'll see the following lines:

define('DB_NAME', ‘exampledatabase’);
define('DB_USER', 'exampledbuser');
define('DB_PASSWORD', ‘database password here’);
define('DB_HOST', 'mysql.example.com');
  1. Select your database name in the left menu.
  2. Click Check all so all tables are checked.
    phpmyadmin drop tables
  3. In the With selected: dropdown at the bottom, select the Drop option.

    After you select the Drop option from the dropdown menu, the page reloads with all information that will be dropped. A Yes button appears on the bottom right.

  4. Click Yes.
    All tables are removed.

Step 2 — Import your database file

There are two methods to import your database:

  • Using phpMyAdmin (simple, limited to 200MB)
  • Using SSH via wp-cli commands (more advanced)

phpMyAdmin

  1. Log into phpMyAdmin.
  2. Click the Import tab in the top menu.
  3. Click the Choose File button.
  4. Locate and upload your SQL file from your computer.
    The database displays the uploaded tables.

SSH

  1. Log into your server via FTP.
  2. Upload your database file into your user's home directory.
  3. Log into your server via SSH.
  4. Run the following command in your user's home directory to import the file into your database.

    Make sure to replace filename.sql with the actual file name of your backed-up database and 'path/to/wordpress' with your website directory:

    [server]$ wp db import filename.sql --path='path/to/wordpress'
    Success: Imported from 'example-backup.sql'.
    

    Large files may take longer but you will receive a confirmation when the import completes.

    If you uploaded a custom wp-config.php file, this command will fail. You must first update this file to use the new DreamHost database credentials.

Step 3 — Upload the wp-content folder

If you created a .zip file of your website files at your former host, you must extract the files first. 

Right-click the file and select the Extract option.

All of your former WordPress files and directories are extracted into a new folder named the same as your domain name. In this folder, you'll find the wp-content folder.

  1. Log into your server via FTP.
  2. Navigate to your website directory.
  3. Delete the wp-content folder since there is currently no content within it.
  4. Locate your backed-up WordPress files on your computer.
  5. Upload only the wp-content folder. 

Extracting on the server via SSH

You can also upload the .zip file to your server and extract it via SSH. This may be a better option if your wp-content folder is very large.

  1. Log into your server via FTP.
  2. Upload the .zip file to your website directory.
  3. Log into your server via SSH.
  4. Navigate to your website directory.

    Replace example.com with your website name.

    [server]$ cd ~/example.com
    
  5. Run the following command.

    Replace wp-content.zip with the actual file name.

    [server]$ unzip  wp-content.zip
    
    This extracts all of the files into a new directory, which is named the same as your domain.
  6. Move the wp-content folder from the newly extracted directory into your website directory.

    Change example.com in this example to your website.

    [server]$ mv example.com/wp-content .
    
  7. Run the following to view all of the files:
    [server]$ ls -la
    
    You should see your wp-content folder along with all of the other WordPress files.
  8. Delete the newly extracted directory:
    [server]$ rm example.com

Step 4 — Update the wp-config.php file

Update the table prefix

Update the wp-config.php file to use the table prefix of the new database you just uploaded. You can view the table prefix in phpMyAdmin. It's the first text of each table. For example, if phpMyAdmin shows this for the options table:

wp_3zby173r_options

Then, the table prefix is: wp_3zby173r_. Update this value in the wp-config.php file.

What if I migrate my domain to a different URL?

The example above shows a domain using the same URL from an old host that is imported to DreamHost. If you're moving your site to a new domain name during your migration, the above steps are the same, but include one extra step. You must update your 'Home' and 'Site URL' as well as your database URLs within the imported database.

There are several ways to do this, which are described below. If you plan to use a plugin to help replace your database URLs, you can use a plugin called "Better Search Replace" (described below) or "Velvet Blues". If you plan to use SSH instead, wp-cli includes Better Search Replace functionality.

Updating your 'Home' and 'Site URL' through wp-admin

Make sure you have a backup of your SQL file. If you make a mistake in the following steps, it may be difficult to fix within a live site.

You can update your Home (Wordpress Address URL) and Site URL (Site Address URL) through the wp-admin page. Go to Settings > General:

manually-migrate-wp-05.png

The following shows how to update database URLs using the "Better Search Replace” plugin:

manually-migrate-wp-06.png

In this example, the following change is made:

  • Old URL: http://www.exampledreamhost.com/
  • New URL: https://exampledreamhost.com/

Run the search-replace tool, which replaces your old URLs with the new one.

Updating your 'Home' and 'Site URL' through SSH

Make sure you have a backup of your SQL file. If you make a mistake in the following steps, it may be difficult to fix within a live site.

You can also use wp-cli commands through SSH to update the URL values. Make sure you're in the domain directory for WordPress:

[server]$ pwd
/home/wp/exampledreamhost.com

Run the following command, which makes a backup to your user directory:

[server]$ wp db export ~/backup`date +"%d-%m-%Y"-%T`.sql

Run the following commands before updating your Home/SiteURL to make sure they're properly pointed:

[server]$ wp option get home
http://www.exampledreamhost.com
[server]$ wp option get siteurl
http://www.exampledreamhost.com/

You can see from the above example URL that the old location is used (http://www.exampledreamhost.com). You can now update the URLs so that it points to 'https://exampledreamhost.com' instead.

  • Old URL: http://www.exampledreamhost.com
  • New URL: https://exampledreamhost.com

Run the following commands to update the WordPress (home) and Site Address (siteurl):

[server]$ wp option update home 'https://exampledreamhost.com'
Success: Updated 'home' option.
[server]$ wp option update siteurl 'https://exampledreamhost.com'
Success: Updated 'siteurl' option.

Run the following command after you update the Home/SiteURL to update the remaining database URLs:

[server]$ wp search-replace 'oldurl.tld/' 'newurl.tld/'

As an extra verification step, you can add the dry-run flag. Make sure there are two small dashes (--) when using this flag; i.e., --dry-run, which performs a command without making any changes. Verify that it is replacing the old URL with the new one.

Another tool you can use is the --all-tables-with-prefix flag, which ensures the change is applied to all of the tables.

For example:

[server]$ wp search-replace 'http://www.exampledreamhost.com/' 'https://exampledreamhost.com/' --all-tables-with-prefix --dry-run
Success: 5 replacements to be made.

The above response confirms that there are replacements to be made. When you’re ready to run the command, make sure to remove the --dry-run flag:

[server]$ wp search-replace 'http://www.exampledreamhost.com/' 'https://exampledreamhost.com/' --all-tables-with-prefix
Success: Made 5 replacements.

After you complete the search-replace function, be sure to run the following command to clear any cache:

[server]$ wp cache flush
Success: The cache was flushed.
The wp cache flush command clears any cache that results from the search-replace functions.

Viewing your site and updating DNS

If your DNS is not pointed to DreamHost, view the following article to view your site using a hosts file.

If the site appears as it should, you are ready to point your DNS to Dreamhost.

See also

Did this article answer your questions?

Article last updated PST.

Still not finding what you're looking for?