Be super-careful when you are following these instructions and be very sure not to edit the web server or database for your actual website! Always be sure that you have backed up your database and web server before doing this, just in case.
So how do you set up a test site for your WordPress blog? First, purchase a separate domain name (anything works) and set it up for hosting. Then, take the following steps to copy your production site (the techie term for your user-visited website) to your test site.
Let’s say your production site is www.mycookingsite.com/blog and your test site is www.mytestsite.com/blog.
- FTP the following files and folders from www.mycookingsite.com/blog/ to your computer or hard drive Note that I’m ignoring your wp-content/uploads folder, as there is really no need to upload your image library):
- On your computer or hard drive, delete the plugin folder for Jetpack if you have it enabled. This is to insure that you do not confuse the WordPress stat engine when you create your test site.
- FTP all of the individual files that are at the same level as the wp-admin, wp-content, and wp-includes folder to your computer or hard drive.
- FTP all of the files from your computer or hard drive into www.mytestsite.com/blog/.
You’ve now made a copy of everything on your web server except your images (no need to have these on your test site).
If you are using VaultPress:
- Navigate to your Backups.
- View your most recent backup.
- Click the Download button and select only the Database.
- Prepare backup and wait for VaultPress to email you with the link to your backup.
- You will receive a gzip file containing your database tables.
- Download the nifty WordPress Database Backup plugin.
- Go to Tools » Backup and run a backup of your entire database.
Step 3: Import your database
- Create a new SQL database through your web hosting company.
- Through your web hosting company, there should be a service called phpMyAdmin. Log into phpMyAdmin using the username and password for your database.
- Select your newly-created database in phpMyAdmin and click on the “Import” tab.
- Browse for your backup file, be sure that the format selected is “SQL”, and click Go.
- In phpMyAdmin, click on your test database, and the table wp_options (or wp_xxxxxx_options). BE SURE YOU ARE IN YOUR TEST DATABASE.
- Find the option name “siteurl”.
- Click the pencil on the siteurl line to edit the information.
- Change the siteurl to your test site.
- In FTP, navigate to the root of your TEST WordPress installation. In our example this would be www.mytestsite.com/blog.
- Open the file called wp-config.php
- Change the values for DB_NAME, DB_USER, and DB_PASSWORD to your test database information.
- Visit www.mytestsite.com/blog/wp-admin and log into your test site. You will log in with the same username and password as your production site.
- Verify that your test site is visible at www.mytestsite.com/blog.
Voila! A perfect copy of your blog. Use your test site to edit your theme, install new plugins to play with, develop new functionality, test upgrades of WordPress or plugins, etc before applying the changes in production.
A few notes:
- If you aren’t on WordPress, but instead have an HTML website, you should still have a test site. Simply FTP the files from your web server to your computer, and then FTP back up to your new domain.
- Your web hosting provider should also allow you to easily password-protect your test site’s domain.
- You should also read the WordPress Codex articles about Restoring Your Database From Backup and phpMyAdmin.
Edited To Add: See comments below for some reasons why you need a test site – this can include changes to your WP theme, or testing out plugins and new functionality, and creating new page templates – and also a shortcut method that doesn’t involve a whole backup of your production site.