Host multiple WP sites on one installation

Most of the basic shared hosting plans will only allow you to use 1 domain name and a limited number of databases. So what do you do if you want to set up more then one WordPress powered site on your hosting plan? Here’s a solution.

Most hosts will allow you to ‘park’ or ‘forward’ additional domains to your hosting plan, but they will show the same site, they can’t be configured to show content from different places. but because the actual files of a WordPress installation are the same, and all the information is stored in the database, we can manage a workaround. What we will do is set up WordPress to use different databases depending on the domain name entered in the browser window.

You will only need to edit 1 file, so this make future updating of your WordPress installation pretty simple. In fact, even if you have your own server, this method might help you keep all your wordpress sites up to date.

Here are the simple steps:

  1. Upload the WordPress files to your server.
  2. Copy the following code to a text editor, and enter your database settings (note: you will have to delete the space between ‘< ' and '?php' in the beginning of the document.)

    < ?php
    // ** MySQL settings ** //
    define('DB_NAME', ''); // The name of the database
    define('DB_USER', ''); // Your MySQL username
    define('DB_PASSWORD', ''); // ...and password
    define('DB_HOST', 'localhost'); // 99% chance you won't need to change this value

    // table prefix, for hosting multiple intalltaions in the same db.
    $table_prefix = ereg_replace('^(www\.)', '', $_SERVER['HTTP_HOST']);
    $table_prefix = ereg_replace('\.', '', $table_prefix);
    $table_prefix = $table_prefix . '_';

    // Change this to localize WordPress. A corresponding MO file for the
    // chosen language must be installed to wp-includes/languages.
    // For example, install de.mo to wp-includes/languages and set WPLANG to 'de'
    // to enable German language support.
    define ('WPLANG', '');

    /* Stop editing */

    define('ABSPATH', dirname(__FILE__).'/');
    require_once(ABSPATH.'wp-settings.php');
    ?>

  3. Save the file as wp-config.php and upload to your sever (where the regular wp-config.php file normally is)

That’s it!

Now, every domain (or sub-domain) you have pointing at this WordPress installation will use a different prefix for it’s tables in the database, so they are totally different, using different settings and data stored in the database.

To add another site, just set up the domain (or sub-domain) ‘pointing’ then visit that domain and follow the wordpress installation process.

Credits: this technique is based on the more complex technique (better for hosting solutions) from OldBrownShoe.org

August 11th, 2006 | Posted in Web, WordPress

Comments:

  1. Payal | August 22, 2006,

    That’s very useful :-) . Thanks! Just when I was thinking about installing a second copy of Word Press for my football newsletter!

    Jan/Payal

  2. Kathalyn | October 1, 2006,

    t

  3. Error | October 28, 2006,

    %

  4. Max | November 15, 2006,

    Hello,

    Super! Really thanks for you hack.

    I have been looking for a solution to have one wp install with differnt domains. I search wordpress.org, all their guides need to change a lot of things in order to it.

    I also tried wordpress mu, but I really can’t figure it out how to have different domains(not sub domain) for different blogs.

    And your hack, only need to modify the config file. It’s a really super hack! Millions thanks!

  5. Max | November 16, 2006,

    I found a problem, if I type something other than “www”, before the domain, it will shows:

    It doesn’t look like you’ve installed WP yet. Try running install.php.

    Will it case potential security problem? Is there any possible way I can fix it? Thanks.

  6. LobsterMan | November 18, 2006,

    hmm, i’ll look into that

  7. ChannelFlix.com | December 6, 2006,

    this is so cool hack – thanks

  8. KMFstudio » New multiple wordpressproject setup | January 7, 2007,

    [...] http://me.mywebsight.ws/2006/08/11/host-multiple-wp-sites-on-one-installation/ [...]

  9. tGriff | January 11, 2007,

    Say, what did you find when looking into the issue max mentions?

    Thanks!

  10. Max | May 17, 2007,

    You need to configure in your apache or dns server to only accept www. Then there will be no problem.

    But recently, I got another problem, I got a domain with hyphen. When I try to install wordpress, it give me error. All you have to do is to add the following line:

    $table_prefix = ereg_replace(‘\-’, ”, $table_prefix);

    You can just add it under $table_prefix = ereg_replace(‘\.’, ”, $table_prefix);

    Hope this help.

  11. PutraWorks Extras » Multi WordPress In One Hosting | June 23, 2007,

    [...] http://me.mywebsight.ws/2006/08/11/host-multiple-wp-sites-on-one-installation/ http://www.idratherbewriting.com/2007/05/31/installing-multiple-versions-of-wordpress-on-the-same-account-but-masking-them-to-appear-as-different-domains/ [...]

  12. Paula | July 2, 2007,

    Really impressive!! Still better than before with the different sites! Congratulations!,

  13. links for 2007-08-07 – .:|randgaenge|:. | August 7, 2007,

    [...] Host multiple WP sites on one installation one database multiple wordpress installations (tags: wordpress mysql database) [...]

  14. Basic Thinking Blog » Wordpress: Templates und multiple Installation | August 8, 2007,

    [...] verweist auf eine Anleitung, die aufzeigt, wie man mit einer Wordpress-Installation mehrere Blogs zugleich bedient. Noch ausführlicher gibts den Spaß auf Wordpress.org. weitere Artikel: « [...]

  15. Webmasterfind Blog » Eine WP-Installation für mehrere Blogs | August 9, 2007,

    [...] ganz interessanten Link bei Schockwellenreiter via Robert gefunden, wonach man mit nur einer Wordpress Installation mehrere Blogs bedienen kann, ohne auf die spezielle Multi-Blog Version Wordpress-MU zu verwenden. Der Trick dabei [...]

  16. links for 2007-08-10 | klick wech | XSBlog2.0beta | August 11, 2007,

    [...] Host multiple WP sites on one installation- This ‘N That (tags: wordpress multiple howto) [...]

  17. links for 2007-08-12 | unblogged.hansi.es | August 13, 2007,

    [...] Host multiple WP sites on one installation- This ‘N That Most of the basic shared hosting plans will only allow you to use 1 domain name and a limited number of databases. So what do you do if you want to set up more then one WordPress powered site on your hosting plan? Here’s a solution. (tags: wordpress software multiple database howto blogging blogs server hosting) [...]

  18. links for 2007-08-13 | Patrick Kempf | August 13, 2007,

    [...] Host multiple WP sites on one installation Most of the basic shared hosting plans will only allow you to use 1 domain name and a limited number of databases. So what do you do if you want to set up more then one WordPress powered site on your hosting plan? Here’s a solution. (tags: wordpress multiple software database howto) [...]

  19. Host multiple WP sites on one installation | August 24, 2007,

    [...] Read the rest of the post by TechJournalist [...]

  20. Makodef_Designer | September 14, 2007,

    Hi,
    Thanks for the great job you did. this plugin is wonderful. However i was wondering if it is possible to have same user accounts for all different blogs. I want to be able to have the admin and other users login to all blogs with the same usernames and passwords. If any body have an idea, please share it. Thank you!

  21. santosh | November 2, 2007,

    Thanks for a good post. I was searching for this information because I wanted another wp blog site for another niche. I will try this now and hope it works. By the way, I am already having a WP installed on one SubDomain in this format: (SubDomain1.MainDomain.com) so how should I modify any existing code to use the same installation for a different subdomain: eg. a proposed SubDomain2.MainDomain.com? Thanks again.

  22. asntosh | November 2, 2007,

    I will try this for a new blog topic. Hope this works. Thanks.

  23. n00bie Challenge – Page 9 – WickedFire – Affiliate Marketing Forum – Internet Marketing Webmaster SEO Forum | November 15, 2007,

    [...] Thought some of ya’s might like this – Host multiple WP sites on one installation- This ‘N That [...]

  24. Stefan | November 20, 2007,

    Thanks! By creating a wildcard dns, and then I added a “*” subdomain (in cpabel) redirecting to my base domain. Now with your tip I have unlimited (subdomainbased) wp instances! Cool buddy.

  25. WP auto/mass installer? – WickedFire – Affiliate Marketing Forum – Internet Marketing Webmaster SEO Forum | December 9, 2007,

    [...] Host multiple WP sites on one installation- This ‘N That but I don’t know php and I’m not sure how this is going to work. Do I just install a new copy of [...]

  26. Durgesh | December 11, 2007,

    Superb and easy man, thanx a lot…..

    I ll add a link to this page on my blog….

  27. Glyn | December 12, 2007,

    I have been doing something similar to this for some time however unless i am missing something, i believe that your method introduces a potentially significant security exposure.

    I think i am right in saying that it’s possible that using this method someone could point their domain to your server and start using your server to host their site.

    I’d start by hosting a new site, I could then get into the theme editor using the administrator id that gets set up by WP on installation. I would then start hacking into your themes and injecting some code in there that I can use to read and write to your database for all of your hosted sites.

    What i would recommend to avoid this is coding something like this:

    switch ($_SERVER['HTTP_HOST']) {
    case “www.mydomain1.com”:
    case “www.mydomain2.com”:
    case “subdomain.mydomain2.com”:
    $table_prefix = ereg_replace(‘^(www\.)’, ”, $_SERVER['HTTP_HOST']);
    $table_prefix = ereg_replace(‘\.’, ”, $table_prefix);
    $table_prefix = $table_prefix . ‘_’;
    break;
    default:
    $table_prefix = “default_’;
    }

    Change default_ to be your default_ site – this is the key that stops unknown domains making a new wordpress site on your server without your knowledge.

    yes, it requires a little extra maintenance – editing the one file – whenever you add a new domain or subdomain but this is not significant – you would simply add another case line containing the domain name.

  28. Mike | December 20, 2007,

    I’m trying to get this to work locally so there is no www prefix. I’ve got wordpress in /wp/ and can setup virtual alias’ /apple/ /banana/ etc. but can’t get them to be recognised by $_SERVER. $_SERVER['REQUEST_URI'] seems to work, slashes taken out et al but wordpress exclaims that their is something besides letters , numbers and under-slashes in the table prefix. Thoughts?

  29. jeremyweiland.com » Blog Archive » A single press for all my words | December 29, 2007,

    [...] was that possible without going down the MU route? The answer is that not only is it possible, but it’s also rather easy. I made a modification to my wp-config.php file that appends a host name prefix to every WP table [...]

  30. The Money Maker Guy » Blog Archive » Setting Up My New Domain To My Existing Wordpress Setup | January 23, 2008,

    [...] links that may be useful for you: Wordpress 2 Multi-Blogging Made Easy Host Multiple WP Sites On One Installation Installing Multiple Versions Of Wordpress On The Same Account But Masking Them To Appear As [...]

  31. Karthikeyan | January 27, 2008,

    Is it possible to create two wordpress blogs like this.

    http://blog.karthikeyan.co.in/
    http://blog.karthikeyan.co.in/blog2/

  32. Chloe Pushchairs | February 14, 2008,

    While this is good, it doesn’t solve the issue fully.
    What is needed is to use one simple backend, where by you can add / edit / delete domains.
    You can also select which categories / posts belong to which domains.

    Each domain is then set via apache2 httpd.conf to pull from the same documentroot. The WP installation then determines which site your on from the SERVER_NAME as pulls the relevant theme / posts / categories.

  33. mg | March 12, 2008,

    Can someone pls explain further how to do the domain ‘pointing’? Thanks!!

  34. mg | March 12, 2008,

    Is domain pointing the same as the “Redirect Domain to URL” option under the Addon Domain Maintenance in the cpanel?

  35. Mehrere Weblogs mit einer Wordpress-Installation | March 16, 2008,

    [...] war der Betrieb mehrerer Wordpress-Blogs, die parallel gepflegt werden mussten. Dank eines Tipps von Sebastian konnte ich nun einfach Abhilfe [...]

  36. Victor | March 18, 2008,

    Why not just use the wordpress MU? This is a multiuser version of wordpress.
    The same used on wordpress.com.

  37. Marketing Articles | April 17, 2008,

    Man, I never thought this is possible. Thanks for this.

    -Jan

  38. thinking geek » Blog Archive » I’m baaack… | April 24, 2008,

    [...] this blog and the sample code that will reveal all.  No rocket science to it, just a slight mod of something someone else has already done. [...]

  39. schuen | April 26, 2008,

    nice! don’t know if it could have a security issue about sql injection when someone types ” or ‘ in the subdomain. just my concern in this case..

  40. Perpetual Moment » Blog Archive » Multiple Wordpress Blogs on Single Host/Installation | May 27, 2008,

    [...] compiled such info from a few such sources, mostly from This ‘N That and used in this [...]

  41. Indian Recipes | June 8, 2008,

    Very useful for me got some websites.. so should see how it works for me

  42. Seonewbie | July 20, 2008,

    Thanks for the tip. I did some googling and found an alternative code which works for my blogs on subdomains:

    $prefix = $_SERVER['HTTP_HOST'];
    $prefix = str_replace(‘www.’, ”, $prefix);
    $prefix = str_replace(‘-’, ”, $prefix);
    $prefix = str_replace(‘.’, ”, $prefix);
    $table_prefix = $prefix.’_’ ; //’wp_’;

  43. Philip Tiangson | September 19, 2008,

    mirrored domain is ok i think. then upload the wp-config.php

  44. Wordpress » Blog Archive » Host multiple WP sites on one installation | September 22, 2008,

    [...] More … [...]

  45. One Wordpress, One Database, Multiple Domains » Thadeus B | December 13, 2008,

    [...] credits: http://me.mywebsight.ws/2006/08/11/host-multiple-wp-sites-on-one-installation/ [...]

  46. Fruits, nuts, and berries » Blog Archive » Consolidated Word Press | January 5, 2009,

    [...] a better solutions.  A little digging on-line came across an approach at This n’ That for modifying wp-config.php to adjust the prefix. It was close, but not quite what I wanted.  Basically, Mr. Kaplan was advocating adding some PHP [...]

  47. nop | January 24, 2009,

    It’s good article . I happy “One Wordpress,One Database,Multiple Domains”

  48. Tusker | November 11, 2009,

    I have virtualmin installed and have 110 of my own websites many of them with wordpress on my local machine. This may reduce the number of files I have to keep with many of the wordpress installs. Though I can not integrate them all but certainly can do it with many of the installs without much in database.

Add a Comment

(required)

(required)


Menu:

Search

Recent Comments

Abram Fehr:
I really like the idea of this plugin. I...

mrbazha:
i am using wp 2.8 and the plugin isn't w...

Chato Stewart:
I like it... but I have a lot of images....

Cai:
Thank you very much for the explanation....

nora:
nice really i will use it...