So many multiple blog requests
There seems to be a lot of people wanting to know how to run multiple WordPress blogs. Some people want multiple blogs with one admin area, so it’s more convenient to post. Some people want multiple authors, each with their own blog. Some people want multiple blogs using the same database (perhaps because of DB restrictions by their host). Others still, want multiple blogs using the same directory so they don’t have to spend more money on server storage and don’t have to update several directories when there’s a new release of WordPress.
If you want multiple users, you can use WordPress MU. If you want separate installations using the same database you can just change the table prefix. However, I fall into the last category.
I figured that all you really need is to assign different databases (or DB tables) to different URLs, but I wasn’t sure how… and I wanted to know if someone had already done it.
Virtual Multiblog
After much searching I found Stephen Rider’s Virtual Multiblog, which was recommended by Alex Tran. It didn’t seem like too much trouble, perhaps a bit more than I was hoping for, but after the initial set-up it should be a cinch to maintain.
I couldn’t get it set up though. I wanted to use subdomains (e.g. subdomain.kristarella.blog), not subdirectories (e.g. kristarella.blog/subdirectory). Even though Stephen’s method works for them, subdomains are a pain in the bum to set up on localhost (on my MacBook), so I couldn’t test it locally, and I didn’t get it working on the server. I probably did something wrong, but I couldn’t find the problem and I didn’t really want to keep messing around with it.
Even though I didn’t get it to work, a lot of people have, so it is probably worth a try.
Update 4th August 2008: Turns out there was a glitch in the configuration for the Virtual Multiblog, so it should definitely work now.
Looks like square one
Going back to my original assumption: I just need to direct different URLs to different databases.
On NFS I can have as many DBs in the same mySQL process for no extra cost (except maybe storage when I put stuff in them) so that’s no problem.
I’ve been getting into conditional tags for WordPress lately. They are a fantastic way to optimise your content to be really useful. Using those gave me an awareness of PHP If statements (e.g. “if” this is the homepage then give the “Home” navigation link the class “active”, “else” give it the regular class).
I thought, “Why can’t I just use wp-config to say ‘if at subdomain.kristarella.blog use one DB, else use other DB’?” My knowledge of Apache+PHP, servers and the inside workings of WordPress are not so hot (read: practically non-existent), so I could see no reason for it not to work, but I also couldn’t find any indication to say that someone had tried to do this (which in itself suggested that it might not work).
Installing multiple blogs from one set of files
Anyway, I made a new site on NFS and pointed both haiku.kristarella.blog and schizography.kristarella.blog at it. I uploaded the WP files to the root directory of the site with a modified wp-config.php.
Technically, I think I code have wrapped just the lines
define('DB_NAME', 'putyourdbnamehere'); // The name of the database
define('DB_USER', 'usernamehere'); // Your MySQL username
define('DB_PASSWORD', 'yourpasswordhere'); // ...and password
with the if statements, but I wasn’t sure, so I wrapped all of the editable configuration stuff in them.
Using this method you could specify different languages and different table prefixes, as well as different databases for the different blogs.
What are those “if” statements doing?
if ($_SERVER['HTTP_HOST']=="haiku.kristarella.blog") {
Basically what those “if” statements are saying is “if you’re at https:\/\/”haiku.”kristarella.blog” do all the stuff after the { until the next }. I added the “or” same address with a trailing slash, just to make sure links with and without slashes go to the same place.
Update 25th October 2008: There was an extra bit in there, I removed it because it was entirely unnecessary.
It freakin’ worked!
I could hardly believe it when it worked (actually I could believe it, but couldn’t really believe I didn’t find evidence that someone else had done it first). I installed a blog at each address. The two different blogs installed tables in the correct databases. I edited the first post in each and it worked fine. I am pretty stoked. It’s so simple!
What can you do with it?
You should be able to run these as independent blogs, but without the hassle of upgrading WP and plugins separately every time. Both blogs will have access to the same theme and plugin folders, but will be able to activate different themes and plugins as directed from the admin area.
Any limitations?
This isn’t a solution to run multiple blogs from the same admin area, but that’s not what I wanted anyway…
The blogs will share an htaccess file, which might limit what you can do there. I’m not sure if you’ll be able to use different permalink structures for each blog. That’s not to say that you can’t use custom permalinks, it just means that the custom permalinks might need to have the same structure. I’ll let you know when I figure this out. I don’t think this is a big deal because a sensible structure on one blog is probably just as sensible on another.
It would be wise to create separate upload folders for the files and images you attach to your posts, otherwise things could get confused and overwritten.
The code and stuff
You are welcome to download the custom config file (right click: download link target, then change the .txt to .php).
If you’re a WP or Apache+PHP guru and can see any glaring problems with this method let me know! If you have any questions about the method, please ask!
Update 25th October 2008: Just discovered that this method interferes with the flash image uploader in WP2.5 and higher (gives an HTTP error “an error occured, please try again later”). If you’re only uploading one image it’s not a problem, just use the browser uploader, but if you really want the flash uploader it sucks. If you have any ideas on how to fix it let me know!
Tracey Grady says
I’ve just completed my site redesign, bringing the site into WordPress for the first time, incorporating a blog for the first time (yes today is the first day of my new blog) and … not just one blog but two. And down the track, three. The site that sits in the root folder has traceygrady.com/blog. I also have a second blog which sits in its own subdirectory – traceygrady.com/portfolio. While it’s structured like a blog for the purposes of uploading new content, I’ve removed the function for people to comment (not necessary).
This has meant uploading WordPress twice, with two separate admins, which has been a headache, but I’m happy with the final result. I don’t know if your solution would apply in my situation or not (I’m working with subdirectories, not subdomains) but it’s interesting to see another approach and another solution to the multiple domain question.
Ben Barden says
Good job on getting all the sites to link to the same files, but I still think you’re going to have to upgrade each blog individually. When you do an upgrade, it’s not always as simple as overwriting the WordPress files. If there are database changes in an upgrade, you’ll need to run the upgrade against all of your databases.
I might be missing something, but I think that’s the main drawback here. Now, if you could write a script to do your database upgrades for each site one by one, that might work…
kristarella says
Hi Tracy! I actually have your blog open in a tab waiting for it’s turn to be read π
I was actually thinking about using this for subdirectories on the train ride home and was going to investigate it (thanks for reminding me!). I see no reason why this wouldn’t work with subdirectories; I think you would need to use symbolic links. I’ll look into it further.
Ben, you’re right that each site and their databases need to be updated as well. I don’t know about you, but the most laborious part of upgrading for me, is replacing the files and making sure that I remember to keep all my modified ones. After that it’s pretty easy to point each site to upgrade.php.
I’ll have a think about that script idea… never tried to write anything like that before, my husband is a whiz at it β he might have an idea.
Tracey Grady says
Symbolic links could be worth a look. I’d be interested if you did decide to explore them further here – thanks for the tip. Hope you liked my blog! I usually have multiple tabs open at any one time as well, all waiting for me to read.
Stephen R says
Hi — I’m the author of Virtual Multiblog.
I used $_SERVER[‘SCRIPT_NAME’] in my system because of a potential spammer risk — using HTTP_HOST instead seemed like an invitation for someone to redirect additional URLs at my site.
The explicit list of acceptable domains fixes this, I think; so you actually have a good solution here. π
I intend to do something like this with VMB, but I have to be careful to preserve backwards compatibility with existing installs. Ah the pressures of a popular system! π
kristarella says
Hey Stephen, I’m a newbie for this kind of thing so it’s interesting to hear your thoughts on it.
How would someone be able to redirect URLs at your site? They’d have to create a DNS that was somehow associated with your site right? I have so much to learn about this stuff… exciting, but frustrating ’cause I wish I knew it already. π
From what I can see, a lot have people have benefited from your solution, so great work!
I see no reason why my method wouldn’t work with an existing WP installation, as long as you create an “if” for that URL with the correct DB details…
Sephen R says
I’m not positive, but I believe that a properly crafted redirect would work. HTTP_HOST simply reflects the URL that the _browser_ used to get somewhere. Again, in your case it’s not a problem because all the acceptable URLs are specified, but in Virtual Multiblog the Easy Setup accepts whatever URL is passed and creates a blog. that’s why I use a variable that comes from the server end, instead of the outside.
To be honest, I’m not terribly experienced myself. i just get on a project and keep bashing away at it until it works. Given enough time, though, my code can be pretty polished. π
David Airey says
Interesting solution, Kristarella. I’ve three sites running on WordPress, and I find the manual upgrading of each a bit of a pain. That said, WordPress is free, so I’m not complaining.
I’ve subscribed to this post, so will let you know if I get any notifications (RE: my last comment).
kristarella says
Thanks David. WordPress is free, but that doesn’t mean we can’t make it easier on ourselves to use it!
Re: getting this to run in subdirectories. One might be able to use REQUEST_URI instead of HTTP_HOST and use the folder as the address. Then it’s a matter of either applying a symbolic link or redirect/rewrite from the folder. However, I could not get this to happen on my computer, I’m not sure if it’s because the method is bogus or because SymLinks and htaccess behave badly on MAMP.
Can anyone shed light on this?
Bob Johnsen says
Thanks for this, Kristarella.
I too would like to run a WP blog from each of several subdomains with only one WP installation. But because I’m so new at this, I want to clear something up.
Do I understand correctly that you have ONE installation of WP and not additional installations in each of your subdomains?
If so, what is in your subdomains to get them to behave like the blog?
When you say “I made a new site on NFS and pointed both haiku.kristarella.blog and schizography.kristarella.blog at it.” is the new site a unrelated site, e.g. http://www.whatever.com or is it http://www.kristarella.blog?
Thanks for you patience.
I have gotten multiple blogs to work in subdomains (with a shared DB ), but I had to install WP in all subdomains. A solution with one WP install with access to it from multiple subdomains would be great.
kristarella says
Hey Bob, sorry for the confusion. I’ll try to address your questions as simply and thoroughly as I can.
The word “installation” seems to be obscured here, because I consider part of the installation process to be uploading files.
No, I have different installations that run off the same set of WP files in one directory. I upload the files to one place that has haiku and schizography pointed at it and then separately go to /wp-admin/install.php for each of them.
The only real convenience here is that I only have to upload files once to upgrade WP and plugins, I still need to go to /wp-admin/upgrade.php for each address when I ugrgrade.
As Stephen said above (but it got eaten by Spam Karma @, sorry Stephen!) every subdomain looks at the same place, but the first thing it find is the wp-config telling it to use a certain database according to where the browser thinks it is.
It is a new unrelated site, merely because I was testing the thing out and didn’t want to kill anything on my main blogs, but it could just as easily be this blog. I could have added two subdomains to kristarella.blog and then replaces the wp-config file with one that included directions to the database for this blog.
In the end I’m not sure if we have the same thing or not! π If you have several sets of WP files with multiple wp-configs pointing to the same database using different table prefixes, then this would be a more convenient solution when it comes time to upgrade.
Bob Johnsen says
Thanks, Kristarella – that clears thing up.
How did you get your subdomains to “point” to the WP domain?
After I figure that out, I’m going to modify wp-config to point to different tables (based on the prefix) instead of different databases – hopefully!
Thanks again.
Bob
kristarella says
You’re welcome Bob.
I’m not sure how it works on other web hosts. NearlyFreeSpeech.Net is set up such that you create a membership, under that membership you can create accounts (essentially funds that pay for your usage). Then, you create “sites”, for which the address is automatically sitename.nfshost.com. To each site you can assign “aliases”, which are generally your domain names.
The reason for all that preamble is that applying subdomains might be different for every web host.
What I did is I made a site called “blogs” then I gave it aliases haiku.kristarella.blog and schizography.kristarella.blog. All aliases for one site use the same root folder. So really it was a matter of clicking the “add alias” button and typing the name.
It’ll be different for other web hosts, but I think decent ones should allow you to apply several address to one site.
Bob Johnsen says
Kristarella,
Everything is working fine – thanks for the help.
My host provides CPANEL for my site, as do many other hosts.
It’s a simplle matter of adding a subdomain from that control panel.
I wanted to use just one database to be shared by each blog.
So, the mod I’ve made to wp-config.php allows me to use a single install of WordPress, a single database and still allow reading and writing unique posts for the main domain and each of its subdomains.
The code can be downloaded by cliking on my name. If it opens up any can of worms such as security issues, is beyond my knowledge, so use at your own risk.
Thanks again.
Bob
Charity says
Wow, you are thorough! π I think I’m gonna have to read this at least twice more to fully comprehend lol!
I’m much like you – I have a hard time understanding all the configurations, what they do, and how everything works together in terms of multiple installations/databases, etc. This looks like a discovery that could be very useful though! I’m already running 5 separate installations of WP and upgrading has become a dreaded task. Nice work!
kristarella says
Thanks Charity. That’s basically why I did this. I don’t want to be updating 5 WP file sets plus plugins!
andre says
great info. I definitely have to reread this a few times to get it in my head lol (newbie here) but for the most part got exactly what you were saying. Thanks for sharing!
Glenn says
If created a script that does this pretty much and makes life much easier for the administrator. It includes and admin interface and an installer. Let me know what you think.
Glenn
matsubokkuri says
I wrote how to manage multiple blogs with small changes like this article.
http://matsu.tymy.net/enblog/2.....ne-server/
My approach is intended for building multiple blogs each path of URL.