15 November 2009 ~ 0 Comments

Serving Multiple WordPress Blogs from a Single Installation (Without WP MU)

I’m serving multiple WordPress blogs on separate domains from a single installation, but without using WordPress MU (multi-user). Yes, I realize you can probably do everything I’ve done here by using WPMU. However, in my situation:

  1. I had already installed 2 versions of WordPress and didn’t want to start all over.
  2. I wanted to easily share plugins and themes across multiple blogs without having to install them over and over. WPMU may do this, I didn’t look deeply into it. I have several blogs which use a few of the same plugins.
  3. I didn’t want to do all the hacking involved in making WPMU serve multiple domains, Again, WPMU may do this, and it’s probably easy, but it seemed to involve a plugin. I’ll rephrase, I didn’t feel like slogging through the steps to make it work.
  4. This struck me as being easier when I thought of it.
  5. I wanted to spend 15 minutes or less to figure it all out.
  6. To summarize: Laaazy!

Maybe this will be helpful to you, and perhaps less daunting than a WPMU install.

Overview

There are 3 folders/directories involved. A lib folder, where you install WordPress, your blog’s web root folder, and a temp folder to move files to for a while.

Here’s what I did (I’ll share all of the shell commands and PHP code below this):

  1. I installed a fresh copy of WordPress in a lib folder.
  2. In my web root folder, I moved all of the existing WordPress files to a temp folder.
  3. I made a few wildcard symlinks for the WordPress files and folders pointing to the lib folder location.

This allowed me to put the wp-config.php for each specific site back into the web root folder later. I did not link index.php, .htaccess, or – as mentioned above – wp-config.php.

  1. I copied the contents of the {temp folder}/wp-content/themes and wp-content/plugins into the {lib folder}/wp-content/themes and plugins folders respectively, so I can use them with all of my blogs.
  2. I made a single easy hack to wp-load.php which, if I upgrade, I’ll have to put back, but it’s a small price to pay.

Then I rinsed and repeated for my other WordPress blogs.

Shell Commands

Here are the commands and the PHP hack (lines with # are comments, which you can skip):

# change {lib folder} etc. to your actual paths, like /home/user/lib etc.
 
# note the periods . at the end of some of these commands.
 
cd {your lib folder}
 
# install a fresh copy of wordpress.
wget http://wordpress.org/latest.zip
unzip latest.zip
 
cd {your web root folder}
 
# move your existing wp files to a temp folder.
mv * {your temp folder}
 
# link the wordpress files.
ln -s {lib folder}/wordpress/wp-*.php .
 
# link the wordpress folders.
ln -s {lib folder}/wordpress/wp-*/ .
 
# link the xmlrpc.php file.
ln -s {lib folder}wordpress/xmlrpc.php .
 
# move the index and config files back.
mv {temp folder}/index.php {web root folder}
mv {temp folder}/wp-config.php {web root folder}
 
# move your site's plugins and themes into
# the lib folder's wordpress plugins and themes folders.
mv {temp folder}/wp-content/themes/* {lib folder}/wordpress/wp-content/themes/
mv {temp folder}/wp-content/plugins/* {lib folder}/wordpress/wp-content/plugins/

At this point your web root folder should only have the index.php file, the wp-config.php file, and the .htaccess file (if you’re using one). You can delete the contents of the temp folder when you’re done with these steps.

You will need to repeat these steps in the web root directories of all the sites to which you wish to apply this method.

The Easy PHP Hack

Edit the {lib folder}/wordpress/wp-load.php file. Change line 20 from this:

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

… to this (2 lines, for the line you commented out, but kept, just in case you need it later, savvy developer you):

20
21
// define( 'ABSPATH', dirname(__FILE__) . '/' );
define( 'ABSPATH', $_SERVER['DOCUMENT_ROOT'] . '/' );

That’s it. Crazy, huh? Let me know if you find this useful.

Tags:

Leave a Reply