Setting Up a Test Site for an Existing WordPress Site

In preparation for an upgrade to an existing custom wordpress site, I wanted to create a sub-domain for testing. For example www.realdomain.com with a test site www.test.realdomain.com. After setting up the site and DNS for test i need to copy the real site to the test site.

All info related to the actual change of the wordpress site and the database comes from this wonderful set of instructions.

Importing Data into the test site.

  • Copy the physical files from one site to another.
  • Export a copy of the real website’s MySQL db
  • Import data into your testsite db.

    mysql -u username -ppassword -h mysql.realdomain.com –default-character-set=utf8 db_name < realdomain_mysql_export.sql

Changing the wp_config.php

  • Make sure to modify the wp_config.php to point to the new db. The setting are found at the top of the file.


    // ** MySQL settings ** //
    define(‘DB_NAME’, ‘db_name‘); // The name of the database
    define(‘DB_USER’, ‘username‘); // Your MySQL username
    define(‘DB_PASSWORD’, ‘password‘); // …and password
    define(‘DB_HOST’, ‘mysql.realdomain.com‘);

Change site & home urls

  • Login to phpMyAdmin.
  • Click the link to Databases.
  • A list of dbs will appear. Choose the one that is the test WordPress db.
  • All the tables in the test db will appear.
  • Look for wp_options. Note: The table prefix of wp_ may be different if you changed it when installing.
  • Click on the small icon indicated as Browse.
  • A screen will open with a list of the fields within the wp_options table.
  • Under the field option_name, scroll down and look for siteurl.
  • Click the Edit Field icon which usually is found at the far left at the beginning of the row.
  • In the input box for option_value, change the URL information to the new address.
  • Verify this is correct and click Go to save the change.
  • You should be returned to your wp-options table.
  • Find the home field in the table and click Edit Field. Note There are several pages of tables inside wp_options. Look for the > symbol to page through them.
  • In the input box for option_value, change the URL information to the new address.
  • Verify this is correct and click Go to save the information.

Changing internal post links

There is one specific field you will need to change and that is the guid, you can also use this to switch links within you posts, but that is not required and left to your preferences.

  • Login to phpMyAdmin.
  • Click the link to your Databases.
  • Choose the one that is the test WordPress db.
  • Look for the name of the table within your database used to hold your post information. Usually it is called wp_posts, but it may have been changed.
  • Clicking the Browse icon or link, open the wp_posts table.
  • Look for the field that holds your post “guid”. It is usually called guid, but it may have been changed.
  • Click the tab at the top for SQL.
  • Switch the old and new URL addresses you wish to update or search and replace within your database:

    UPDATE wp_posts SET guid = REPLACE (
    guid,
    ‘http://www.realdomain.com’,
    ‘http://www.test.realdomain.com’);

  • Make sure that the names of wp-posts and post_content match the tables and fields within your database. Change them if not.
  • Ensure that the ONLY content you want to change are within the little single ‘quotes’ . Make sure EVERYTHING is spelled right and that you are sure this is correct.
  • click Go.
  • At the top of the screen will be generated a list of how many of the tables and fields have been changed.
This entry was posted in Web Related. Bookmark the permalink.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.