Okay gang, I’m back with more handy-dandy tips from the war-front. This past weekend, I decided to go live with ChrisHilbig.com. Given the fact that this has been the first time I’ve ever developed a WordPress site and than tried to transfer everything from my local computer running a MAMP environment to my webhost was a nightmare to say the least. In other words, it involved lots of wasted time in front of my Mac. During this debacle, my local copy of WordPress decided to wig out on me. My admin panel became unusable. I couldn’t even edit my posts. Fortunately, I had a week-old backup of the site.
Here’s the ideal process that I was shooting for:
- Create a backup of the local SQL database.
- Import the backup to the webhost.
- Upload my WordPress files.
- Remotely edit my wp-config.php file for the different database online
- Run the Search and Replace Tool script to fix the online database. (The origional database contained links that worked only on the local server.)
Now you would assume that this would had been a sane and logical plan. (And it wasn’t.) Now here were the hurdles I had to hump over:
- I was able to figure out how to properly export a SQL database, but I didn’t know how to import it correctly. (Lots of time wasted here.)
- HUMAN-ERROR: I didn’t set the nameservers correctly. (I swore I did.)
- I think I had a corrupt copy of WordPress locally (I couldn’t properly load anything in my Dashboard correctly.)
- I didn’t understand where to install WordPress in my webhosting account. (I know, another bone-headed moment. For a while I assumed WordPress had magical powers over the server. 😛 )
Now, lucky for you, I plan to save you a lot of pain. (Especially if you’re currently where I was.) In this post, I plan to walk you, step-by-step, on how to correctly transfer your local WordPress website to your webhost so it can run live.
Step 1 – Exporting your Database:
Here’s what I should had done:
- In my local copy of WordPress click Dashboard > Plugins > Add New.
- Do a search for WP Migrate DB.
- Install the WP Migrate DB plugin.
Why do I want you to install this plugin? Because you’ll kill two birds with one stone. WP Migrate DB with neatly export (or data dump) your local SQL database. That means so far you get to avoid phpMyAdmin. The other great thing about this plugin is that it also does the find and replace on URLs and file paths that are contained inside your WordPress’s database.
Why is this important? I’ll explain: Your WordPress’s database contains all sorts of information. (content, categories, tags, etc.) The most import data that’s inside your database are the links, and on your local computer they probably start out with something like http://localhost:8888/wordpress/… Unlike an old-school HTML website where we have the luxury of linking to other pages within a website without having to start with a domain.(Ex: <a href=”/dir/index.html”>linky</a>) A link in WordPress will look something like, <a href=”http://www.mydomain.com/my-awsome-post/”>linky</a> On top of that, all of the images within your posts start with a domain. To move your WordPress site from one server to another, you have to correct every link with the correct domain name. (The only possible exclusion is if your using the same domain name. Which is not our situation.) This is why WP Migrate DB is a God-send. It does find and replace locally inside your copy of WordPress. Let’s see how it’s done…
- Under Plugins > Installed Plugins, we find WP Migrate DB and click Activate
Click Tools > WP Migrate DB. Within this panel is where the magic happens:
WP Migrate DB screen. Click to enlarge.
If you had taken a good look at the image above, this’ll be self explanatory. Where it says New address (URL), enter your domain name. (EX: http://www.mydomain.com) Within the New file path, we want to type in the filepath on the server to your web root directory/folder. The web root will either be labled public_html or www. It’s the folder that’ll contain your website’s files. Usually it’ll be similar to the file path to your computer’s user or home folder. (Because all modern computers have something called user accounts. This allows everyone in the family to use the same PC without messing up each other’s data.) For example on a Windows PC, the path to your account will look something like “C://Users/myAccount”. On a Mac it’ll look like, “Hard Drive/Users/myAccount”. If your server runs a variant of Linux, it’ll look like “/home/myAccount/www”. If you’re not sure, visit your webhost’s support site or politely contact their technical support.
Once you drop in the correct info, you’ll click the Export Database button and in a minute or so, your web browser downloads an exported SQL database with all of the correct links inside.
Step 2 – Importing your Database to the New Server
- Now we need to import your SQL database into your webhost’s server. Unfortunately we just can’t FTP it.
In my case, I installed a fresh copy of WordPress via my webhost’s copy of Softaculous. It installs WordPress in my web root directory (so we’ll only need to type in http://www.chrishilbig.com and not http://www.chrishilbig.com/wp/). Then it’ll automatically create (via the WordPress installer) a brand-spankin’ new database for my site. I’ll show you what I did to import my SQL database.
1.) I opened up phpMyAdmin in my web browser.
2.) Selected my WordPress’s new database in the left-hand panel.
3.) I click on the Import tab. Click on the Choose File button, and pick my SQL file. Then I click the Go button. That uploads the SQL file onto the server and replaces the lack of data in your database with the data from your upload. (See the image below.)
This is what you’ll see if you’re successful:
If you have a perfectly good WordPress site on your local computer, You can use phpMyAdmin on your web host’s server to create a new database.
- Click on the Databases tab.
- Under Create Database, type in the name of your new database. (You’ll likely use the same name as on your local server.)
- Also select your collation. You’ll likely use utf8_general_ci. You should use whatever the server’s default is.
- Click the Create button and you’ll have a fresh database.
- Last use MySQL Databases to ensure you have user access to the database, and you create a new password for your copy of WordPress to use to access the database. It’s pretty straight forward. (This can also be done via phpMyAdmin if it displays a Privileges tab when viewing your database.)
- Update your wp-config.php file to insert the correct name, user, and password.
Step 3 – Upload the Images
I upload all of my images sitting inside my local WordPress site > wp-content > uploads to the same folder on the live server. Click on the image below:
Step 4 – Test the Site
I of course tested out my website and everything works like it should.
After that, I just installed my plugins. Amazingly the database remember’s their settings. Thankfully that was about it. In four easy steps, you can now transfer your WordPress site from your local server to your webhost’s server.
This is one of those magical moments that only occur around mid-night for some reason. Here’s a page I wish I had looked at, http://codex.wordpress.org/Changing_The_Site_URL. This somehow changes the URL in the SQL database as well. I did all the steps on this page for another site I’m working on. (I had to transition a WordPress site from a sub-domain to a regular domain.) I’m obviously still green at WordPress, so I’m not sure at what point things worked out.
© 2013 Chris Hilbig