Mango



Thread: Many blogs with one url and one database

Created on: 07/14/12 05:39 PM

New topic Reply    Page: 1  

Replies: 8
NBostaph


NBostaph's Gravatar
Joined: 01/29/12
Posts: 16

07/14/12 5:39 PM

Is it possible, and could I get a quick rundown on the steps, to setup a large number of blogs using the same db and url? What I'm looking to do is programmatically create new blogs on the fly, then access them using a url something like: www.mysite.com/MangoBlog/index.cfm?BlogID=2.

I read over the instructions at https://www.modernsignal.com/multiple_mangoblog_instances, but they appear to be slightly different from what I'm trying. He's using a separate CF Application for every blog, and another virtual directory for every one as well. Being that I expect the number of blogs on my server to number in the tens of thousands (though most with no posts and the remainder with 10-20 posts) that seems unwise in my case.

Can MangoBlog be setup to run under one application and one DB but run multiple blogs based just on the blogID? I've tried doing a little experimentation myself, but I'm running into a few problems:

- I have no idea how to get MangoBlogs to recognize a url variable as a blog ID
- Certain values in some tables look like a hash instead of simple data and I'm unsure how to add to these tables
- I'm unsure which tables are actually 'necessary' to add data into to create a blog, and which are merely helpful for advanced functionality

Any advice would be greatly appreciated.
Link | Top | Bottom
NBostaph


NBostaph's Gravatar
Joined: 01/29/12
Posts: 16

07/21/12 2:14 PM

Can anyone offer any thoughts at all?
Link | Top | Bottom
Laura

Wizard
Laura's Gravatar
Joined: 01/29/05
Posts: 1521

07/22/12 10:12 PM

Hi,

Answering directly to your questions:

- Can MangoBlog be setup to run under one application and one DB but run multiple blogs based just on the blogID?

Yes, that is what the "[prefix]blog" table is for. Normally, however, those are for different URLs.

- Certain values in some tables look like a hash instead of simple data and I'm unsure how to add to these tables

I am not sure what you need this for. The only hashes are for passwords.

- I'm unsure which tables are actually 'necessary' to add data into to create a blog, and which are merely helpful for advanced functionality

Just an entry in the blog table. And provided you want to setup authors, then the author table and author_blog to tell Mango who has access to which blog.

- I have no idea how to get MangoBlogs to recognize a url variable as a blog ID

This requires you to write a component that makes the distinction and sets the blog instance for the request. A sample component can be found at: http://www.mangoblog.org/downloads/Facade.cfc.txt
Please note that the only thing you need to change is the line that says:
<!--- decide which blog id to show, maybe get it from the URL --->
<cfset key = "MY_BLOG_ID"/>

That is where you set the current blog id. Only change that. You can also use the settings you get in init if you need that for anything. Those settings can be set in the config.cfm file.
Then you need to tell Mango to use that component as "facade". See sample:
http://www.mangoblog.org/downloads/config.cfm.txt
The key part is where it says:
<!-- this is what you need to add: -->

Now, having say that, I am not sure it makes sense to have a URL like www.mysite.com/MangoBlog/index.cfm?BlogID=2
The reason is that everything will have to have that blogid, for example, any given post would need to be something like:
www.mysite.com/MangoBlog/post.cfm/mypost?blogid=2
Mango cannot produce urls like that and therefore you won't get past the homepage of each blog.
The other issue is the admin. There too, you would need to have the blogid appended, and that is impossible to do.
A better approach is to use URL rewriting for something like http://www.mysite.com/BLOG_1/ (I can show you a sample of that for Apache), but you would still have many hairy problems in the admin. I wouldn't go there if I were you and I don't have any sample of that.
The best approach of all is to use a URL like http://BLOG_1.mysite.com. I have successfully used that with no issues.
Link | Top | Bottom
NBostaph


NBostaph's Gravatar
Joined: 01/29/12
Posts: 16

07/23/12 4:09 PM

Laura,

Thank you so much for all the advice. I will see about picking up another domain for my site so that I can give each blog it's own second-level domain. Or do you think that a third level domain, such as http://Blog1.blogs.mysite.com would work okay?

I'll play around with this when I have some more time later this week and let you know how it goes.

Thanks again,
Nicholas
Link | Top | Bottom
Laura

Wizard
Laura's Gravatar
Joined: 01/29/05
Posts: 1521

07/23/12 4:13 PM

That works too.
Something to take into account is that this works for Apache, but IIS is not very good at handling wildcard subdomains (ie: *.blogs.mysite.com), as it requires (at least last I looked) that you add each subdomain as a host header individually.
Link | Top | Bottom
NBostaph


NBostaph's Gravatar
Joined: 01/29/12
Posts: 16

07/23/12 4:14 PM

Oh, and to answer your question, a few of the fields that appear to be hashes are:

author.ID
author_blog.author_id
category.ID

Basically, all of the ID fields. I'm not much of a DBA. I would have expected these to be more 'autonumber' integer fields. I see that these are simply varchar fields. Would it work okay to use numbers here that I increment myself, or is there some meaning in the long code that is currently used?


Also, you mention that the best way to structure the database is a separate set of tables for each blog, but is this really best in my case? At 10,000 blogs that would be over 100,000 tables; I would guess MySQL has some sort of table limit we'd be in danger of reaching. Shouldn't we instead have all those entries in one set of tables filtered by blog ID?

Thanks!
Link | Top | Bottom
NBostaph


NBostaph's Gravatar
Joined: 01/29/12
Posts: 16

07/23/12 8:36 PM

Something to take into account is that this works for Apache, but IIS is not very good at handling wildcard subdomains (ie: *.blogs.mysite.com), as it requires (at least last I looked) that you add each subdomain as a host header individually.


Wow, ouch. I'll have to look into that. I thought they actually improved that in the newer versions of IIS, but I haven't actually tried it myself yet. Thanks for the advice so far; hopefully I can take it from here. :)
Link | Top | Bottom
NBostaph


NBostaph's Gravatar
Joined: 01/29/12
Posts: 16

07/26/12 7:03 AM

Well, I finally had the opportunity to try and work with this today. I'm getting stuck trying to add an author. As you pointed out the passwords are all hashes. Could you please tell me how I can generate these hashes in order to create a new user?

Thanks.
Link | Top | Bottom
NBostaph


NBostaph's Gravatar
Joined: 01/29/12
Posts: 16

07/26/12 10:45 AM

Alright, I got it all figured out! :)

For users who may find this information useful in the future:


For the password: <cfset hashPassword = hash(user.id & password, 'SHA')>


For the user ID: It's just a uuid ("createUUID()")


To remove functionality, such as the file manager (bad idea for blog hosting), simply delete each record from role_permission that has the associated permission, then delete the permission from permission. I'd recommend a backup before doing this, of course.


And...if you can't figure out how in the world to reach the admin panel, it's at www.yourblog.com/admin. I added a link to it on the footer of my theme.


Many thanks for all the help Laura! :)
Link | Top | Bottom

New Post

Please login to post a response.