With the new version of CloudNotions.com under construction, I needed a way to clone the live site (aka “production”) down to my PC. This would allow me to make sweeping changes and try out things locally, without altering the live website until we were ready. Read on for details…
One note of caution for those who might try this: WordPress (or any multi-tier web app) is not designed to be easily moved. It can be done, but the process requires a bit of surgery. If a database console gives you nausea, you’ll want to steer clear.
The basic steps are:
- Copying the web server and database content
- Installing WAMP
- Importing the files and data
- Updating the data to stop pointing at the live site
Disclaimer: this process has been tested for moving WordPress to a local PC for development purposes. Use caution if you are moving the live site to another live location, as the steps will be slightly different.
If the above summary didn’t scare you off…let’s get started!
1. Copying the Web Server Files
Begin by logging on to your hosting provider’s FTP location. For GoDaddy/cPanel, navigate to Hosting > File Manager > web root
You should see folders for wp-content, wp-admin, and other nifty things.
2. Copying the Database Data
Since we are already connected to our hosting provider, go ahead and navigate from the main screen (often cPanel) to Databases > PHP Admin. Open the databases on the left-hand tree diagram. Pick the database that has the wp_posts table and click Export.
3. Installing WAMP
WAMP is a tool that allows you to run the Apache web server, MySQL database, and PHP scripting on Windows. There are pre-configured packages that auto-configure WAMP. I recommend Bitnami: https://bitnami.com/stack/wamp
(Side note: if building a WordPress site from scratch locally, Bitnami also has a WAMP+Wordpress package.)
(Side note #2: Bitnami also has packages for Amazon and other cloud providers – https://bitnami.com/cloud)
The WAMP install steps are outside of the scope of this article, but they provide a very simple wizard.
Important: make sure to note the database name and password.
4. Importing Web Files
Navigate to the web server directory in your WAMP instance. It defaults to a location similar to:
Unzip the files from step one here. Once complete, you should have a folder structure like this:
You can check that the web server is running by opening a browser and going to “localhost”, or clicking Go To Application in the WAMP manager tool.
5. Importing Database Data
Here’s where things get tricky. The WordPress database does not like to be moved.
Use the WAMP manager to navigate to phpMyAdmin. (Make sure it’s the local version, not your live database.) Import the database that you previously saved.
6. Updating the Data
The WordPress database has configuration settings with the old address. Fix this by navigating to phpMyAdmin > SQL and entering the following. (Replace “LIVESITE” with the live site’s address.)
<code>UPDATE wp_options SET option_value = replace(option_value, 'http://www.LIVESITE.com', 'http://localhost') WHERE option_name = 'home' OR option_name = 'siteurl';</code>
Next, fix the addresses on individual posts by running these two SQL statements:
<code>UPDATE wp_posts SET guid = replace(guid, 'http://www.LIVESITE.com','http://localhost');
UPDATE wp_posts SET post_content = replace(post_content, 'http://www.LIVESITE.com', 'http://localhost/testsite');</code>
7. Fix WP-Config Settings
We’re almost done. Navigate to the location of your app server files (C:\BitNami\wampstack-5.4.14-0\apache2\htdocs). Find the wp-config file that was copied from the live site. This one isn’t relevant, so delete or rename it. Now open http://localhost in your browser.
You’ll be prompted to create new WordPress database settings. Click “Create a Config File” and enter the database info that your made note of back in step 3. Click submit, then close and confirm you have a new wp-config file.
8. Permalink Settings
Navigate to http://localhost. You should now have a working site. One final settings change – navigate to WP Admin > Settings > Permalinks. Click to change the type, Save, then change it back.
(Side note: I have no idea why this is needed, but see this article for details. https://wordpress.org/support/topic/problem-moving-wp-now-only-the-home-page-works)
You now have a working instance. You can use this to test custom code, advanced plug-ins, etc. Enjoy!