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.
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.
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:
- Go to the blog’s home directory
- Find and open the wp-config.php file (it’s just text, use WordPad or something)
- Just after the opening comments, you should see something like the text below, where I’ve circled the 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.
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:
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.