How to use single WordPress codebase for multiple sites?

Here I present “simple” solution to use single wordpress installation directory for multiple sites. Main purpose for this is to enable easier WP updates as well as theme and plugin updates. Today WP is very popular and sitä vaivaa same problem which PhpBB and Windows system have; hackers get interested of it which accelerates security updates. I have more than ten wordpress sites online and I found it tendentious task to update each of them separately so I figured out how to do it easier task. I got good starting point from this article:

http://www.ryanmcdonnell.com/multiple-blogs-one-wordpress-install-zero-code-changes/

Single codebase

This will require basic knowledge of unix commands and handling files. And of course setting up basic WordPress from web browser interface.

  1. download newest WordPress
  2. extract WP to some general or global server directory. I use /usr/share/wordpress and there I have ./wordpress2.8.4/ and ./current/ directories so that in future I can keep older versions alive. Current is a symbolic link to the newist version. It can be created something like: $ sudo ln -s wordpress2.8.4/ current
  3. create a new wp-config.php file with one line:
    <?php require('wp-local/wp-config.php'); ?>
  4. download necessary plugins and themes and extract them to the appropriate directories on wp-content directory

Single WP codebase

Multiple sites

Next steps are needed to set up WP for any website:

  1. create wp-local directory to the site root, for example: $ sudo mkdir /var/www/my-site.com/wp-local
  2. create wp-config.php to the wp-local. You can do it by copying wp-config-sample.php, for example: $ sudo cp /usr/share/wordpress/current/wp-config-sample.php /var/www/my-site.com/wp-local/wp-config.php
  3. edit database preferences (DB_NAME, DB_USER, DB_PASSWORD and DB_HOST), security keys (AUTH_KEY, SECURE_AUTH_KEY, LOGGED_IN_KEY, NONCE_KEY) and absolute path: define(‘ABSPATH’, ‘/var/www/my-site.com/’); from wp-config.php you just created.
  4. create uploads directory to the wp-local directory for media uploads
  5. create .htaccess file with single line: php_value include_path “.:/var/www/my-site.com/wp-local/:/var/www/my-site.com/” You can use this .htaccess file to handle permalinks on WP just by adding code, that WordPress generates for you from Settings->Permalinks, putting it jsut after php_value.
  6. create symbolic link from the single codebase to this blog: $ sudo ln -s /usr/share/wordpress/current blog
  7. create index.php with single line:
    <?php header('Location: ./blog/'); ?>

    This redirects website to the blog as a default page, but it also allows you to create other pages, that may have nothing to do with WP

  8. point browser to the site and you are ready to install WordPress as normal!

You need to realize, that all sites use same plugins and themes directories. To use separate for each site, or even both original installation plugins and client plugins would need some more modification on WP code.

Finally you can or actually need to change uploads directory path from WordPress administration panel: Settings->Miscellaneous

Miscallenous settings

I have used this procedure both for setting up new WP sites and changing old sites to use single codebase and it works like charm.

  • Share/Bookmark
  1. Review sites and blogs under investigation
Programming

If you enjoyed this post, please consider to leave a comment or subscribe to the feed and get future articles delivered to your feed reader.

Comments

12 Responses to “How to use single WordPress codebase for multiple sites?”
  • I don’t know If I said it already but …Excellent site, keep up the good work. I read a lot of blogs on a daily basis and for the most part, people lack substance but, I just wanted to make a quick comment to say I’m glad I found your blog. Thanks, :)

    A definite great read….Barbra Scurley

  • Oscar says:

    Thanks for the tip. But, why not just use Wordpress MU? It will do the work for you. What are the advantages of this approach?

    Cheers!

  • admin says:

    Im not sure what features MU has, but I needed separate or individual database, domain and additional plugin, theme and media directories for each WP blog. This has been asked some times, so I need to check out MU and see main differences, if there are any.

  • Tnelson says:

    Hey very nice blog!!….I’m an instant fan, I have bookmarked you and I’ll be checking back on a regular….See ya

  • The main benefit of MU in this case would be that you get a global admin for managing your sites/blogs. However by default MU is all in one database, unless you use a multi-db-extension such as the one provided my WPMUdev (http://wpmudev.org/). Also I see the approach you’re using as conceptually more simple. Each site is separate, you’re simply using the same codebase.

    I also see a distinct advantage in your approach: if a WP upgrade breaks one site, you can keep it linked to an older WP version until you have time to fix it.

    WP 3.0 (should be out sometime next year) is supposed to merge the regular WP and WPMU codebases, so we’ll see then how much sense this will make… but thanks for the post, very enlightening!

  • admin says:

    Thanks for feedback Dan. You have a great concept of services on your site, I like it. Good to know about new WP 3.0, I need to keep eyes open for that. And yes, one reason for this directory structure is, that I can keep current working version, develop version or any other test version and easily manage plus switch between them from local WP index and htaccess file. I’m using same principles with all my web app at the moment.

  • Ben says:

    Perfect idea to keep multi domains with single code, however I wonder what if you like to have WP serving your root domain?
    using your method will force a dir.

  • admin says:

    I dnt know exactly what you mean, but I actually use index.php to redirect to blog directory, which is a symbolic link to a single code base. Then URL changes, true, but you could do it with .htaccess and modrewite so that index.php -> blog dir. That way you have blog on root, but can have other content, files and directories on root as well.

  • Ben says:

    what i mean is to have WP serve the root domain
    like http://www.example.com
    and NOT http://www.example.com/blog

  • admin says:

    I have done that by making a whole domain root as symbolic link to wordpress directory. But then domain is totally used for wordpress and nothing else, which is not suitable for all cases. I tried to use mod_rewrite yesterday to achieve same by htaccess but it wasnt as easy as I figured. Need to think if there is any option… usually there is. :)

  • Guest says:

    I found this extremely useful and I wanted to add my input to contribute. You can still use a root install of WP using this method.

    You copy the index file out of the install base (which is symlinked) and put it in the root. Change the require command path to point to your install base directory. Like…

    require(‘./wordpress/wp-blog-header.php’);

    So in your root you have:

    wordpress install base (sym link)
    .htaccess
    index.php
    wp-config.php

    Make sure to change gobal settings to note the location of the install base and the root address under general settings.

    Last thing for me to make this perfect is find a way to pull themes specific to an install without letting them be available to other installs. Any ideas?

Leave Comment

(required)

(required)