Create a WP staging website in 6 steps w/o a Plugin

This tutorial assumes you have some prior knowledge of PHPmyAdmin, adding Domains, and copying files.

How-to Create a WP Staging Website:

1. First thing you need to do is to create a subdomain (subdomain.example.com). This allows your staging website to run in a separate folder, not affecting your main website files.

vestacp
VestaCP

2.Now that you have setup your subdomain, the next step is to copy the database from your live site to your staging site.

Log into phpMyAdmin, and select your current live database, clicking on the Operations tab in the menu bar.

phpMYAdmin
phpMYAdmin

In the Copy Database To box, enter the name of your staging database (if you haven’t created it yet, click “CREATE DATABASE before copying”). Click Go to run the copy, this could take longer on larger databases.

Copy database
Copy database

3. After your database has copied, you need to select it from the sidebar on the left and rename the URLs in the database. To do this, click on the SQL tab in the menu bar and add the code below to Run SQL queries.

SQL
SQL

Remember to update the URL value: NEW_URL = staging.example.com, ORIGINAL_URL = example.com

UPDATE wp_options SET option_value = REPLACE(option_value, 'ORIGINAL_URL', 'NEW_URL');
UPDATE wp_postmeta SET meta_value = REPLACE(meta_value, 'ORIGINAL_URL', 'NEW_URL');
UPDATE wp_posts SET guid = REPLACE(guid, 'ORIGINAL_URL', 'NEW_URL');
UPDATE wp_posts SET post_content = REPLACE(post_content, 'ORIGINAL_URL', 'NEW_URL');

4. After copying your database, you need to copy your WordPress files to the staging server.

5. After copying your data, update your wp-config.php file to use your new staging database connection details. You can use FTP to accomplish this, or if you are an expert, you can use Terminal:

cp -a /PATH/TO/INSTALL /PATH/TO/STAGING

6. Remember to add a disallow all to your robots.txt, and/or update your Search Engine Visibility settings or you might be penalized with duplicate content.

Settings > Reading > Search Engine Visibility

Click “Discourage search engines from indexing this site”

Isaac Adams-Hands

Full Stack Developer, Digital Marketer, and InfoSec enthusiast. He received his Bachelor’s Degree from the University of Western Sydney and his Business Diploma from Georgian College before joining various marketing positions in search portals, e-commerce, higher education, and addiction recovery services.

Follow @ twitter

Related posts

Add a shortcode to add_shortcode in functions.php

This drove me a little crazy one afternoon. I had to add a gravity forms shortcode to a new add_shortcode script in functions.php To accomplish this, I added this to my code: ‘ . do_shortcode($content) . ‘ Here is how it looks in its working example. I work best by watching. Too many people just… Read More

Dynamic Page Listings in #WP

Here is how-to dynamically list all children pages associated under a parent page in WordPress. This allows you to change and update pages without updating a sidebar widget/page, and removes the need to create numerous distinct sidebars/sections. To enable this code, add it to your WordPress themes functions.php file, then add the shortcode to the… Read More