Make WordPress Core

Opened 4 years ago

Closed 4 years ago

#24563 closed enhancement (worksforme)

Allow multiple sites on a common code-base

Reported by: ergonlogic Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.5
Component: Upgrade/Install Keywords: has-patch
Focuses: Cc:

Description (last modified by SergeyBiryukov)

It would be nice to be able to run multiple independent WordPress sites on a common code-base. I'm not talking about the multisite feature, but rather what's documented here: http://codex.wordpress.org/Installing_Multiple_Blogs.

Since we can already keep our wp-config.php separate from the WordPress code-base, this can be accomplished with symlinks, and a simple patch (attached). Basically, the file structure could look something like:

/var/www/example.com/wordpress -> /var/www/wordpress-3.5/
/var/www/example.org/wordpress -> /var/www/wordpress-3.5/

The vhosts would then look like this:

<VirtualHost *:80>
ServerName example.com
DocumentRoot /var/www/example.com/wordpress


<VirtualHost *:80>
ServerName example.org
DocumentRoot /var/www/example.org/wordpress

The patch to wp-load.php simply changes settings ABSPATH from this:

define( 'ABSPATH', dirname(__FILE__) . '/' );

to this:

define( 'ABSPATH', $_SERVER[ 'DOCUMENT_ROOT' ] . '/');

From my (admittedly limited) testing, this appears to work just fine. With a couple small tweaks along the same lines to wp-cli (https://github.com/wp-cli/wp-cli/issues/478) it appears to work just fine from the command line too. For a bit of background on where I'm coming from with this, see: https://drupal.org/node/1044692#comment-7473232.

I'm relatively new to WordPress, so forgive me if this (or something like it) has already been suggested and shot down for some technical reason. I haven't seen anything that looks related in searching through the issue queue.

Attachments (1)

docroot_abspath.diff (484 bytes) - added by ergonlogic 4 years ago.
Patch to set ABSPATH based on DocumentRoot

Download all attachments as: .zip

Change History (5)

4 years ago

Patch to set ABSPATH based on DocumentRoot

#1 @SergeyBiryukov
4 years ago

  • Description modified (diff)
  • Version changed from trunk to 3.5

#2 @dd32
4 years ago

FWIW, this is already possible when using WordPress installed in it's own directory: http://codex.wordpress.org/Giving_WordPress_Its_Own_Directory

  1. /var/www/wordpres-common/
  2. /var/www/dd32.id.au/index.php + wp-config.php
  3. /var/www/dd32.id.au/wordpress/ -> /var/www/wordpres-common/
  4. Set /var/www/dd32.id.au as the DocumentRoot for a VirtualHost

repeat 2-4 for each site.

I take it a step further and add a custom wp-content directory to my domain folders, and use the WP_CONTENT_DIR + WP_CONTENT_URL defines in my wp-config.php file as appropriate.

Last edited 4 years ago by dd32 (previous) (diff)

#3 @frederick.ding
4 years ago

  • Cc frederick.ding added

#4 @nacin
4 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to worksforme
  • Status changed from new to closed

dd32 described but one way to do this. You could also have a simple switch in wp-config.php (for as little as just $table_prefix) and serve everything off the same document root, no symlinks required.

WordPress can be installed anywhere, even directories inside of the doc root. So this change would actually break a lot of existing sites.

Note: See TracTickets for help on using tickets.