How to Move a WordPress Blog to Your VPS

The process of setting up a VPS with a WordPress blog is simple enough… but it can get a lot more complicated if you need to move an existing blog off another hosting service. This guide is here to help simplify things.

Note: this is a long article. Work through it step by step. I assume you know how to set up a VPS with a domain name and an empty database.

Before The Move

Make backups of everything. You can never have too many backups. Seriously.

You’ll also need to decide whether to close your blog during the move or leave it open – if you do the latter, you may need to move individual comments and stuff afterwards, which is just annoying.

Personally, I always take the easier route and announce “planned maintenance” for the move, then close the blog to do it. Cleaner, easier and less chance of messing up.

First step

Create a new (empty) database on your VPS and note the database name, username and password. This will be your new blog database.

On The Old Server

Download everything in the wp-content folder to your computer or somewhere in cloud storage. You will need this stuff when you’re done setting up a VPS version of the blog.

Tip: Some people suggest taking the wp-config and .htaccess files but I do things slightly differently, creating an entirely new database rather than trying to trick the system into thinking it has the old one on a new server. And I don’t fiddle with .htaccess so there’s nothing to take.

While your wp-content folder is downloading, log into your old server’s control panel and find the phpMyAdmin option. You’re going to export a copy of all the blog data.

Find your blog database

If you know the blog’s database name, select it from the list. If you used something like Simple Scripts when you set things up, you’ll need to find the database name by following these steps:

  1. Go to the blog’s home directory
  2. Find and open the wp-config.php file (it’s just text, use WordPad or something)
  3. Just after the opening comments, you should see something like the text below, where I’ve circled the database name:
how to move your wordpress blog - find the database name

Database name

Look for the database in your phpMyAdmin list and click it. You can check whether it’s the right one by selecting the wp_posts table from the list and hitting “Browse” to see the data. The first entries should look familiar as your earliest posts and pages on your blog. Hit the “Home” button to return to the top level.

At the top level menu, select “Export”.

The only option you need to change here is “Save as file”. You can use the “zip” or “gzip” (more common) option to make the download smaller if you have a large number of posts on your blog.

Tip: Since we’re assigning a new database to the blog, you don’t need to worry about dropping tables, databases or anything else. Now you see why I work this way!

Click the “Go” (or similar) button to begin the data download.

Once the download is complete, you’ll need to edit the file to change the database name. A lot of people prefer to name the new database on the VPS exactly the same as the old one but I’ve found that hosting providers often do things differently – for example, GoDaddy’s VPS prefixes database names with an account name whereas iPage’s shared hosting doesn’t – which makes it very hard to get everything to match.

In the downloaded SQL file (which is just text and will open in WordPad), find the line that starts with “CREATE DATABASE” (near the start) and delete it.

how to move a wordpress blog - sql changes

Changes in the SQL file

The following line says “USE ‘database_name’” (with the name of the old database). Change that to read “USE ‘new_database_name’” (with the name of the new database you set up on your VPS). Save the edited file.

On the VPS

Upload all the WordPress setup files as usual. Do NOT run the install.

Overwrite the wp-content folder with the one you downloaded from the old server. Upload the entire thing, warts and all.

Go into phpMyAdmin on the VPS and select your new database (the one you created back at the first step). Click the “Import” option and point it to the SQL file you downloaded from the old server (the one you edited). Import the data.

If you get an error, you probably forgot to take out the “CREATE” line and change the database name in the SQL file you uploaded.

Once the data import is complete and your old wp-content folder has been uploaded, you can go to the blog’s URL.

Tip: If you haven’t switched the nameservers over yet, you’ll have to do that now and wait for propagation to take place (or access the VPS using the IP address and full path to the domain’s WP install).

You’ll be presented with the standard WordPress config screen. Press “Create a Configuration file”, then “Let’s go” to get to the following screen:

how to move a wordpress blog - WP setup screen

WordPress setup options

You’ll need to provide the new database name (from setting up a VPS database earlier), the username and the password you set.

The last two parts you shouldn’t need to change – most VPS setups use “localhost” as the database server and unless you specified otherwise on your old hosting, all the WP tables in the database use a “wp_” prefix as standard.

Tip: You can press the “Install” button if you want – WordPress detects that the tables are already there and just asks you to carry on by logging in. There’s no risk of destroying everything!

After The Install

Check all your plugins, theme options, posts and everything else got transferred properly.

There’s also one foible you’ll need to fix. When you import a WP database, the individual pages aren’t always rebuilt. This means that your blog looks normal but it actually doesn’t work. At all.

To fix this, log into your blog as admin. Go to Settings -> Permalinks. Choose any option and click “Save Changes”. Then switch it back to your preferred setting and click “Save Changes” again. WordPress forces a rebuild of the links and everything works perfectly.

All done!

Bookmark the permalink.

Leave a Reply

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