Single database for multiple instances

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

Solutions Collecting From Web of "Single database for multiple instances"

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.

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', '' );
    define( 'WP_SITEURL', '' );

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?

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