Dynamically assign a Subdomain name to an existing Subdomain directory.

jayb1 - August 25, 2009 - 04:50

Hi Drupal newbie here so I apologize in advance if this is too mediocre of a request.
I am using Ubuntu packaged with MySQL, Apache, PHP and Drupal6.
In the least I am attempting to dynamically assign a Subdomain name to an existing Subdomain directory. That is where I am currently stuck.
For example, I would settle for a quick method to dynamically assign Subdomain names, (based on what a user enters) and map then to the already existing Subdomain directory that I already created.
I was able to modify the .htaccess file, to be able to accept Subdomain name based on a subdirectory I created under the /usr/share/drupal6 directory. Unfortunately, it appears that I really need to point this to the /etc/drupal/6/sites/subdomain1.mysite.com (OR Drupal location) at least this is my current thought.
I have yet to figure how to get it to point or utilizing the Subdomain (i.e. directories where the setting.php, subdomain1).
*** So I guess my real question is if I am using a single Drupal codebase then how does Drupal know when someone enters the public directory structure /usr/share/drupal6 to direct them to one of the subdomains/etc/drupal/6/sites/subdomain1.mysite.com?
Currently all I can get the .htaccess to point to the public directory /usr/share/drupal6 but not to /etc/drupal/6/sites/subdomain1.mysite.com.

Ultimately I would of course like it much better if I could simply have the users enter a few parameters and the Subdomain and database be created on the fly based on the name the Subdomain that user entered using existing templates and database that I setup to utilize. I see a few possibilities and I am exploring them,
But until I can find this I will simply make do with creating all these manually in advance then doing a dynamic mapping of the user entered Subdomain to the real Subdomain directory. First things first.
Thanks in advance for any assistance that you could offer.
Sincerely,

You should set up your

greg.1.anderson - August 25, 2009 - 21:02

You should set up your website to serve files from the drupal root folder (e.g. /usr/share/drupal6, if that's what you're using); when a request for a subdomain is received, Drupal should automatically look for a settings.php based on the subdomain name. For example, http://subdomain1.mysite.com would look first for /usr/share/drupal6/sites/subdomain1.mysite.com/settings.php and next would look for /usr/share/drupal6/sites/mysite.com/settings.php and finally would also check /usr/share/drupal6/sites/default/settings.php.

Drupal isn't set up to create databases on the fly. It doesn't seem like a good idea from a security standpoint. If you want to be able to create and manage a large number of Drupal sites, check out the provision module and the Aegir hosting system (disclaimer: I'm not using them myself at the moment...)

Good luck,

- Greg

How do I map the /usr/share/drupal6/newsub to /etc/drupal/6/site

jayb1 - September 5, 2009 - 16:26

Greg,
Thanks for the feedback. I am able to created the Subdomains now in the /usr/share/drupal6 directory by simply adding a directory. However, in keeping with Druplas approach for multi sites they recommend using the /etc/drupal/6/sites/mysubdomain.mydomain.com approach.
So the issue is now:
How do I get the /usr/share/drupal6/newsub (The one accessable to the world) to actually redirect to /etc/drupal/6/sites/mysubdomain.mydomain.com? In addition how can I take the information that a user enters as a requested Subdomain name and map this to the /etc/drupal/6/sites/mysubdomain.mydomain.com subdomian?
I greatly appreciate your assistance on this.
Sincerely,

Your question does not

greg.1.anderson - September 8, 2009 - 04:52

Your question does not provide enough information to allow for an answer. When you say "I am able to created the Subdomains now in the /usr/share/drupal6 directory by simply adding a directory," it seems to imply that you are using some feature of your web server that says, in essence, "map any request for newsub.mydomain.com to the folder /usr/share/drupal6/newsub". You should not use this feature to provide multiple sites with drupal.

Instead, make all of your subdomains serve files from /usr/share/drupal6. When your webserver receives a request for newsub.mydomain.com, it will server the page /usr/share/drupal6/index.php. This file (drupal's main entry point) will look for the 'q' parameter in the request query, and the domain that the request was received from, and will serve the appropriate page from the appropriate drupal site's database based on these values. In other words, it is /usr/share/drupal6/index.php that is consulting /usr/share/drupal6/sites/newsub.mydomain.com/settings.php; the web server is not configured to serve files from /usr/share/drupal6/sites/newsub.mydomain.com as the root of newsub.mydomain.com.

Consult the documentation for your web server for instructions on how to do this, as the steps vary from one web server to another.

Good luck,

- Greg

 
 

Drupal is a registered trademark of Dries Buytaert.