Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I would like to create two instances of WP on a single domain. For example, I would like wp1.domain.com and wp2.domain.com to use a single database (same comments/posts). One for production and one for development. Is this possible, and if so, how?

share|improve this question
    
I built a framework just for this: github.com/developdaly/WordPress-Skeleton It's meant to handle any number of development/staging/production environments which can share the same database. It works for multisite as well. –  developdaly Dec 13 '12 at 5:04
add comment

3 Answers

up vote 3 down vote accepted

It's considered best practice to have two separate databases (one for production, one for development) then migrate the database as detailed here. If you, for example, install a database-changing plugin on one but not the other, you risk breaking one of your sites until you duplicate those changes over. If you're working late tweaking code, you might end up breaking your live site and not realizing it until the angry client calls to rip you a new one.

Really, keep your production and development sites completely separate. It will save you a number of hassles down the road.

If you only have access to a single database, set each site to use a different database prefix. This ensures easy duplication with standard SQL tools while keeping separate dev/prod environments.

share|improve this answer
add comment

I don't think it's possible, since there is some info on the DDBB that's specific to a certain URL, such as the siteurl and home options, plus many others like navigation links (if you're using WP's menus), etc.

Probably the best option it's to keep different databases (which it's also a good idea if you're planning to do admin stuff on the development site) or, even better, to setup a local development enviroment

share|improve this answer
add comment

The simplest way of doing that is just conditionally defining the environment variables in wp-config.php like this:

/** Define alternate home and siteurl based on $_SERVER host var */
if ( strpos ( $_SERVER['SERVER_NAME'], 'wp2' ) !== false ) {
    define( 'WP_HOME', 'http://wp2.domain.com' );
    define( 'WP_SITEURL', 'http://wp2.domain.com' );
}

I would set your 'home' and 'siteurl' options to the production URL, and just test for the dev environment and set the constants above on your development server. Or, if they're actually in separate directories, you can skip the $_SERVER check and just define those variables there.

You've got to think about what you're doing to share the wp-content folders though, especially the uploads folder. And the plugins folder could also be an issue. If you get an error with a plugin on your dev folder, WordPress will deactivate that plugin on your production site - is that what you want?

share|improve this answer
    
I am mostly concerned with replicating post & comment data. I understand there is post meta data, and it may be tied to a plug-in –  Kermit Jun 6 '12 at 17:59
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.