Automated subdomain creation

tusharkanta's picture

I have a requirement where as soon as user creates one site using aegir hosting tool, system should automatically create 2 subdomains of that site. For instance, if some user creates a site called in the aegir hosting tool UI, system should automatically create 2 sites and All three sites, and should all share one DB with many tables (about 190 tables) being shared across all 3 sites and few tables (around 50) being independent through table prefixing option.

Is it possible to do it only by using aegir and customizing it?


by using combination of aegir and other module like domain access ?


by any other technique ?

Thanks in advance.


build a drush module

aaronbauman's picture

The operations to create sites use drush provision commands.
You can tap into the various operations using various hooks in the form:


MY_MODULE = the name of your module.
PHASE = pre or post
OPERATION = install, verify, enable, delete, etc.

Put together a module, drop it in /var/aegir/.drush, and walla - you can hook into the provision process and do what you need to. With some trial and error, I was able to use drush_my_module_post_provision_install to create a svn repository for all new sites and check in an initial revision.

Additionally, since you're setting up multisites, you'll need to hook into hook_provision_drupal_config (see provision/platform/, line ~191) to create the database prefixing code you'll need in your settings.php files.
I think that will be a function of the format <em>MY_MODULE</em>_provision_drupal_config.

Finally, you might need to look at hook_provision_apache_dir_config or similar, since you won't be able to use .htaccess files in your sites.

we don't support shared tables at all

adrian's picture

and it's unlikely we will ever support them.

it means that all those sites are not upgradeable separately, and it will give you endless troubles when it comes time to roll out new versions of your code.

We have a requirements where

tusharkanta's picture

We have a requirements where few tables have 20+ million records which gets updated almost daily. All the sites need to use same tables. It will be impossible to duplicate each table across all the sites. How best we can create sites through aegir that will use such tables. Please advise.

have you considered

adrian's picture

using a single site and using something like domain access.

so it's one site that appears to be multiple sites.

Domain access can have 1

tusharkanta's picture

Domain access can have 1 primary site and other multiple subdomain based sites. But it might not be possible to create many primary sites (for instance:,, etc). We can use aegir to create many such primary sites and subdomain module can be used to create subdomains like and for each of the primary domains. Each of those sites will share few huge central tables. Will this concept work?

sharing tables will not work.

anarcat's picture

sharing tables will not work. aegir rewrites your settings.php and purposefully drops the $db_prefix settings you may have in there so this will not work. see the following for more details:

can't the domain module work without sharing tables? seems a bit of a crude way to make this thing work...

Thanks for the reply

tusharkanta's picture

Let me explain what we are doing.
We have a site
Contents are separated country wise (uk and us) through domain access module. Through domain access module and subdomains.

Some of the contents are shared and some of the separated.

The enormity of content size is as follows:

There are around 20+ million product nodes for us subdomain and 10+ million product nodes for uk subdomain. Till now this is working fine.

But we want to introduce white labeling now. Users might create their own site (for instance: making as a platform, but can have their own modules enabled etc. Aegir fits in well there. After user creates the site, system should automatically create subdomains and and these 2 will use product nodes of and respectively. . So many tables will be shared across these multiple sites and some tables will be independent.

Which is the best way to achieve this?
If we share tables across aegir sites, will anything break apart from not supporting upgrades? Thanks in advance.

as aaronbauman said below, i

anarcat's picture

as aaronbauman said below, i believe you are overcomplicating things and will have trouble upgrading that setup. it will not work with aegir.

i'd be curious if domain.module would help without sharing tables.

Thanks for the reply

tusharkanta's picture

Thanks for the reply anarcat.

Please read the following scenario and explain me how domain module alone will work without aegir:

There is already a master site named existing.
Then there are 2 subdomains called and They are subdomains of

These 3 sites (one main domain and 2 subdomains) are already existing at present.

Now a business user wants to create a white label called using as a platform

Can domain access module help there ? I guess no

I think can only be created by aegir. Am i making sense?

multisite is overcomplicating things

aaronbauman's picture

My explanation above is a theory about how to accomplish what you were setting out to do on a technical level.
However, It sounds like you could accomplish your goals with clever use of rewrite rules, pathauto, and taxonomy (or a similar tagging mechanism).

Multisite is good when the sites you're running are totally different. But, splitting drupal's databases among many tables is asking for problems in general. Yes it's possible, yes drupal has theoretically supported it since 4.7 or whatever, but I would avoid it like the plague (from personal experience).

If you can come up with a solution to "fake" the multisite and use rewrites, I would absolutely go that route.

i would use multisite and domain access

mvc's picture

would the 'white label' sites be independent clones of the original sites or would they be a different view of a subset of the content from the original sites?

if you want them to be clones, then it would make sense to drop your use of table prefixes and then create them via aegir. but then you'll need to export your product data from the master site and re-import it into the others periodically. do you really need table prefixing?

if you want them to have access to the original dataset of 30m products, i would suggest using just multisite and domain access, since that module was created precisely to solve the problem of multisites with one shared database and some shared content (with table prefixing possible but not required). you can use domain views to control which is presented where, or even write a custom domain access module if needed.

either way, note that single sign-on across domain access multisites now (unfortunately) requires table prefixes ever since the shared sign-on module was deprecated for security reasons. so if you require that feature, you'll never be able to use aegir, since it explicitly disables table prefixing.

For SSO, you should use the Bakery module

anarcat's picture

Bakery is the module that's running I haven't personnally tried it, but if it works here, it will probably work for your site. ;)

Hi MVC, Thanks for your

tusharkanta's picture

Thanks for your reply. It will be a clone of the site. But not all tables will be independent. For example, we don't want to clone the 30million+ product tables. Similarly some of the tables can be shared. For instance, a user can create a site called out of using aegir. But after is created using aegir, system should automatically create subdomains like and which will share most of the contents of and

What is the best way to achieve this ? Thanks for replying

as i said above, if you're

mvc's picture

as i said above, if you're not cloning the entire site, i would personally forget about using aegir and just use domain access, which is a very powerful set of modules with an extensive user community. the multisite group can likely help you with the details.