Only fill this in if you're a spammer huh? Your name :
Your email :
Your message :
Oct
11th
2007

Multi-domains on a single evo install

Posted in : Techno Babble

  • First of all, it helps if you have a domain name(s) and some webspace .... luckily I have plenty of both, so that was easy.
  • Next, setup your main domain on the server however the hell you normally do.
  • Once you've done that you should have a *webroot* folder, mines called "html" in a totally unimaginative way.
  • Ok, we're halfway there, next you need to create your subdomain/2nd domain, and tell it to use the same webroot folder as your main domain ... that's kinda the important bit ;)
  • The rest is easy, upload your b2evolution files to the webroot folder and meander through the install in the usual fashion.
  • Now for the fun and games :
    1. Wander into the blog settings in admin and slap the relevant url in the absolute url box
    2. Press save
    3. This is probably the most compicated bit "repeat from step 1 for each domain/subdomain you have"

That was tough huh?

The same folder?

Ok, this is the drawback to this method, all of your domains/subdomains share the same folder so, unless you trust all your users, ftp access is probably out of the window ;) ...... obviously, the fact that it's a single install makes maintenance/upgrades a lot easier.

The only two ways I know how to set this up ( unless you class "ask yer bloody host" as an answer ):

  1. In your control panel, when adding a domain/sub domain, choose the same webroot folder as your main domain. I'm not sure all hosts have this as a standard option though
  2. Crack open your vconf file, or whatever it's called, and add in the required aliases, mine looks a bit like this :

    Code:

    <VirtualHost *:80>
    ServerName innervisions.org.uk
    ServerAlias www.innervisions.org.uk waffleson.co.uk www.waffleson.co.uk
    DocumentRoot /path/html
    suPHP_UserGroup user
    </VirtualHost>

Yay, multiple domain/subdomain blogs on a single install, nirvana is achieved ....... actually, not quite. You'll soon start noticing that you're only logged in when you're on the main domain, so if you're on a subdomain ( or another domain ),private/protected posts suddenly become lost in the ether, and any edit/publish/deprecate/delete icons that might normally be shown in your skin! ....... "where have they gone?" I hear you ask. The problem is, you're not logged in and, it gets worse, you can only login to the main domain ( the one you set your $baseurl for ) .... yer screwed.

The two steps to heaven

You can actually solve the login problem in a couple of ways, which you use depends if you're using subdomains or domains, if you're using both then ( weirdly enough ) you'll use both solutions ;)

For separate domains you need to crack open your /conf/_basic.config.php and uncomment some bits that are niftily commented by the evo team to show you how to do it ;)

PHP:

/**
 * $baseurl is where your blogs reside by default. CHECK THIS CAREFULLY or nothing will work.
 * It should be set to the URL where you can find the blog templates and/or the blog stub files,
 * that means index.php, blog_b.php, etc.
 * Note: Blogs can be in subdirectories of the baseurl. However, no blog should be outside
 * of there, or some tricky things may fail (e-g: pingback)
 *
 * IMPORTANT: If you want to test b2evolution on your local machine, do NOT use that machine's
 * name in the $baseurl!
 * For example, if your machine is called HOMER, do not use http://homer/b2evolution/blogs/ !
 * Use http://localhost/b2evolution/blogs/ instead. And log in on localhost too, not homer!
 * If you don't, login cookies will not hold.
 *
 * @global string $baseurl
 */
$baseurl 'http://localhost/b2evolution/blogs/';
// Use the following if you want to use the current domain:
/*
if( isset($_SERVER['HTTP_HOST']) )
{    // This only works if HOSt provided by webserver (i-e DOES NOT WORK IN PHP CLI MODE)
    $baseurl = ( (isset($_SERVER['HTTPS']) && ( $_SERVER['HTTPS'] != 'off' ) ) ?'https://':'http://')
                            .$_SERVER['HTTP_HOST'].'/';
}
*/

For subdomains you need to meander over to conf/_advanced.php and play with the cookies, which has once again been niftily commented in a useful way by the evo team ;)

PHP:

// ** Cookies **
 
/**
 * This is the path that will be associated to cookies.
 *
 * That means cookies set by this b2evo install won't be seen outside of this path on the domain below.
 *
 * @global string Default: preg_replace( '#https?://[^/]+#', '', $baseurl )
 */
$cookie_path preg_replace'#https?://[^/]+#'''$baseurl );
 
/**
 * Cookie domain.
 *
 * That means cookies set by this b2evo install won't be seen outside of this domain.
 *
 * We'll take {@link $basehost} by default (the leading dot includes subdomains), but
 * when there's no dot in it, at least Firefox will not set the cookie. The best
 * example for having no dot in the host name is 'localhost', but it's the case for
 * host names in an intranet also.
 *
 * Note: ".domain.com" cookies will be sent to sub.domain.com too.
 * But, see http://www.faqs.org/rfcs/rfc2965:
 *    "If multiple cookies satisfy the criteria above, they are ordered in
 *    the Cookie header such that those with more specific Path attributes
 *    precede those with less specific.  Ordering with respect to other
 *    attributes (e.g., Domain) is unspecified."
 *
 * @global string Default: ( strpos($basehost, '.') ) ? '.'. $basehost : '';
 */
if( strpos($basehost'.') === false )
{    // localhost or windows machine name:
    $cookie_domain '';
}
elseif( preg_match'~^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$~i'$basehost ) )
{    // Use the basehost as it is:
    $cookie_domain $basehost;
}
else
{
    $cookie_domain preg_replace'/^(www\. )? (.+)$/xi''.$2'$basehost );
 
    // When hosting multiple domains (not just subdomains) on a single instance of b2evo,
    // you may want to try this:
    // $cookie_domain = '.'.$_SERVER['HTTP_HOST'];
    // or this: -- Have a cookie domain of 2 levels only, base on current basehost.
    // $cookie_domain = preg_replace( '/^( .* \. )? (.+? \. .+? )$/xi', '.$2', $basehost );
    // fp> pb with domains like .co.uk !?
}
 
// echo $cookie_domain;

Now that wasn't hard .... was it ;)
¥

Trackback URL (right click and copy shortcut/link location)

Trackback url for this post
Note : This trackback url is time limited so use it within 30 minutes or the SpamHound will snarl at you.

http://waffleson.co.uk/z/?k=36752602633103238a92880404fc898d116163d714eeef4e5

Replied on : 10/11/07 @ 12:44 pm #1

Not read it in specific detail yet, but it looks like a monkey could do that, gosh its SO SIMPLE :)

Gz
 
 

Replied on : 12/31/07 @ 05:17 am #2

great!
 
 

Replied on : 01/20/08 @ 10:55 pm #3

Hello !,
I reached this post surfing some other one on b2evo site.
Thanks for your description, this is *VERY* useful !.
I am looking how to trigger some external script from b2evo, in order to configure the DNS and webserver alias when new blogger is registered. Would you have some ad about it ?.
 
 
¥åßßå users avatar

Posts : 845

Joined : 10/05/05

Location : 127.0.0.1

Reply to comment 14530 by ¥åßßå

Replied on : 01/21/08 @ 02:59 pm #4

Hi there,
One thing you may be able to do is to add a wildcard dns/alias setting which would basically point everything.yourdomain.com to your blogs folder.

¥

I may have opened the door, but you entered of your own free will

 
 

Leave a comment

Your email address will not be displayed on this site.
Your URL will be displayed.
About you

Just fill in the bits you want, none of it is required



Your email address will only be used to send you adverts for viagra and rolex watches.



(Line breaks become <br />)
Leave a comment
Code:
=> :!: :?: :idea: :) :D :p B) ;) :> :roll: :oops: :| :-/ :( >:( :'( |-| :>> ;D :)) 88| :lalala: :crazy: >:XX :o