Moving wordpress

Steps:

If changing database or moving hosting or domain:

  1. Make a DB backup, using a backup tool or phpmyadmin – we need the sql file in a format we can edit.  (Note you might want to take the opportunity to clean up the options table first, and get rid of any orphaned options – there are plugins to help with this. )
    1. Find the siteurl options – fix the url if necessary (eg if moving domains) – this will help avoid the “white screen” problem.
    2. If you want to change the table prefix, now is the time.  Do a search and replace on `wp_ and “wp_ and ‘wp_. Yes you could do wp_, but hey this is safer what if there was a wp_ in the middleof a word?
    3. You may to just check if anywhere there are any domain or location specific urls specified with absolute urls. Eg: search and replace “http://yourolddomain/youroldwplocation/” with “./”

Moving hosts

Check whether the localhost specification needs to change in wp-config.php file.  Eg: going to icdsoft, you may need localhost:/tmp/mysql5.sock.

Moving wordpress code location

  1. Move the WordPress Code
    1. Move your entire word press directory to where you want to keep it – eg: down a level: eg to …/wp
    2. Optionally move the wp-content sideways or somewhere else
    3. Create a copy of the index.php file and put it into the original directory
      1. Edit index.php and insert the new subdirectory into the file path.
        Ie: change
        require(‘./wp-blog-header.php’);
      2. to
        require(‘./wp/wp-blog-header.php’);

      3. Save and Exit.
      4. Test –  Browse to the blog url.  You should see your website but lacking style!
    4. Define where Content should live,
      1. leave it there or move it sideways.. whatever…
      2. Now go to the new subdirectory wp and edit the wp-config.php.  Add or change the following lines at the end of the file
        • define( ‘WP_CONTENT_URL’, ‘http://yourdomain/yoursubdirifany/wp/wp-content’);
        • define( ‘WP_CONTENT_DIR’, $_SERVER[‘DOCUMENT_ROOT’] . ‘/yoursubdirifany/wp/wp-content’ );
        • define(‘WP_SITEURL’, ‘http://yourdomain/yoursubdirifany/wp’);
      1. Check you also have at the end of the file
        • define(‘ABSPATH’, dirname(__FILE__).’/’);
        • require_once(ABSPATH.’wp-settings.php’);
      2. Save and Exit.  Test – refresh the browser window and now there should be style!

Move the Uploads folder

  1. You must check out what the upload path spec is doing. In 2.7 the default will put uploads under your main wordpress folder in a wp-content folder.   This does not make sense.   If you have problems – use the full url path. It may be a good idea to update this using multiple websites from one instances. Logon as admin, got to settings > miscellaneous and change before uploading

Test, Test

  • Primarily you will be testing your plugins that they are using these wordpress constants
  • Browse your website, check all the areas where plugins should be doing something
  • Test all the areas that do some kind of upload (shops, members)
  • do all the actions, comments, subscribe etc
  • Login as admin, browse around, check all is as it should be!
  • If you find a plugin that does not work, first check you have the latest version, then tell the author by commenting at wordpress or on the plugin page .  It would be nice if you would log it here too.

Multiple Blogs, Domains with wordpress

The configuration features now available in wp-config.php now offer you a great deal of flexibility if you have multiple domains parked at the same host or multiple blogs where you wish to share one or more of the database or  the code.

Move the wp-code

First of I’d suggest keeping the wp-code out of the main directory.   Read Giving_WordPress_Its_Own_Directory

This will give you the flexibility of serving other code more easily.  Eg: one parked domain may be redirected to a subdomain not using wordpress at all.

Defining the siteurl overrides the option table.  Plugin developers should use this and not fetch it from the options table.

define('WP_SITEURL', 'http://example.com/wp');
define('WP_HOME', 'http://example.com');

Index.php example:

if (strstr($_SERVER['SERVER_NAME'], "onedomain.com")) {
    // serve up the default wordpress index.php code
    define('WP_USE_THEMES', true);
    require('./wp/wp-blog-header.php');
}
elseif (strstr($_SERVER['SERVER_NAME'], "anotherdomain.com.))
{
    // redirect to the subdomain, passing the query string along
    header( 'Location: http://subdomain.anotherdomain.com'.$_SERVER['REQUEST_URI']) ;
}

If statement

In the wp-config.php file, code an if statement similar to above  to determine what your url request is (eg: which domain name) and set the appropriate field to achieve the effect noted below.

Plug-in authors beware – plugins must be tested with these various schemes

Plugins must use these constants or run the risk of not working on some installations.  Users should check all aspects of their plugins.

Configuration values

Multiple Installations in One Database

// You can have multiple installations in one database if you give each a unique prefix
$table_prefix  = 'r235_';   // Only numbers, letters, and underscores please!
define('DB_NAME', 'MyDatabaseName'); // Example MySQL database name

Share Code, but not Themes or Plugins

Move the wp-content directory and define the following:

define( 'WP_CONTENT_DIR', $_SERVER['DOCUMENT_ROOT'] . '/blog/wp-content' ); and
define( 'WP_CONTENT_URL', 'http://example/blog/wp-content');

Warning if Moving

Don’t forget to change the settings in the Miscellaneous settings for your uploads

Advanced Options

There are more advanced options too, using for example:

  define('TEMPLATEPATH', get_template_directory());
  define('STYLESHEETPATH', get_stylesheet_directory());

Note: beware:
Multiple domains sharing the same wordpress installation must have the same permalink structure - changes to one will edit the .htaccess, which will then override the previously set permalink.