
Drupal Tutorials
Drupal Sub domain configuration
Prerequisites
You should be comfortable with server configurations and will to get your hands dirty (a bit).
You should be comfortable with server configurations and will to get your hands dirty (a bit).
Rate this tutorial
Comments (12)
Saturday, February 21, 2009
By ariene
Big thanks to Ariene Ellefsen for writing this great little tutorial for DrupalSN, thanks Ariene!
Hello Everybody,
I’d like to share this tutorial with you about how to set up subdomains on your website using Drupal and a few server tricks.
So why use subdomains?
Subdomains offer 3 main advantages:
- Google treats a sub domain as a totally different website from its main domain
- You can use any keyword(s) as a subdomain
- It doesn't cost you any extra money to set up a subdomain (with most host companies).
So, if your agent website is hosted on a domain name like, "ellewebdesign.com", you can set up an unlimited number of subdomains (providing you host company permits it, check with them), such as...
service.ellewebdesign.com
portfolio.ellewebdesign.com
blog.ellewebdesign.com
project.ellewebdesign.com
portfolio.ellewebdesign.com
blog.ellewebdesign.com
project.ellewebdesign.com
And so on. The good news is that the keywords in the subdomain name carry SEO importance, just like the keywords in the domain name. Combine that with the fact that Google sees each subdomain as a separate website, you've got a great way to create lots of backlinks.
Here's another Google advantage. As it is now, each search results page on Google will show a maximum of two listings from the same website. But if you set up subdomains, it's possible to dominate all 10 listings on the first results page of Google!
So subdomains can offer big SEO (Search Engine Optimization) advantages as well as looking professional.
We have all heard by now the advantages of having a blog for promoting your website. So why not try it and create a blog using this technique and subdomains for your site!
Once you have your blog, adding a link to it on your menu takes a couple of seconds, and voila - your blog is up and running. This is the part where you feverishly start posting articles about your niche market, your product, or your service, and link to your website from each article.
Blogs are amazing: Search Engines love them, and they generally get good PR very quickly.
Good luck and I hope this tutorial will show you the importance of using subdomains.
Subdomain Setup
Let's get stuck in and set up our subdomains.
If you want to test this you can download XAMPP or WAMP and have your local computer run like a server. Both packages are free and easy to set up.
For these examples we are using XAMPP for Windows.
For these examples we are using XAMPP for Windows.
It's highly recommended that you test this locally before working on a live server and we recommend checking with your host before setting up subdomains as some hosts will offer a control panel to set up subdomains quickly and easily.
Step 1: Server Setup
1 First let’s create a DNS entries file for the website (The purpose of creating the DNS entry is to be able to test the sub domains in our local machine)
DSN (Domain Name System) tells your server where a subdomain or web address should be directed to. It's basically a way of putting a human readable name over the top of an IP address.
2 To find the host file (that we can add our DSN entries to) go to: C:\WINDOWS\system32\drivers\etc\ then open the "hosts" file using Notepad.
Add the following entries, then save and close the "hosts" file:

3 Next we need to alter our Apache VirtualHost settings to look for the new subdomains.
Locate your servers httpd.conf or httpd-vhosts.conf file (which one you have depends on your server setup), if you are using XAMPP you'll find it at:
c:\program files\xampp\apache\conf\extra\httpd-vhosts.conf
On Linux you will find your httpd.conf file at:
/etc/httpd/conf/httpd.conf
So go ahead and add the following to the bottom of your httpd.conf or httpd-vhosts.conf file:
Listen 80
<VirtualHost *:80>
DocumentRoot "C:/Program Files/xampp/htdocs"
ServerName localhost:80
</VirtualHost>
<VirtualHost www.site.local:80>
DocumentRoot "C:/Program Files/xampp/htdocs"
ServerName www.site.local:80
</VirtualHost>
<VirtualHost www.blog.site.local:80>
DocumentRoot "C:/Program Files/xampp/htdocs"
ServerName www.blog.site.local:80
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:/Program Files/xampp/htdocs"
ServerName localhost:80
</VirtualHost>
<VirtualHost www.site.local:80>
DocumentRoot "C:/Program Files/xampp/htdocs"
ServerName www.site.local:80
</VirtualHost>
<VirtualHost www.blog.site.local:80>
DocumentRoot "C:/Program Files/xampp/htdocs"
ServerName www.blog.site.local:80
</VirtualHost>
You'll need to restart Apache to this change to take affect.
On Linux use: apachectl -k restart
On XAMPP you can use the XAMPP control panel or restart your computer.
Great!! We already have two subdomains but to make it works we need to create a folder inside of our apache installation.
Step 2: Drupal "sites" folder setup
1 Go to: C:\Program Files\xampp\htdocs and create a folder called "www.site.local", this is where your default Drupal installation will reside so add all your Drupal installation files to this folder.

Proceed with the Drupal installation and test the site on your local machine.

Step 3: Let’s create our subdomain
We going to create a "blog" subdomain (blog.site.local) for our main Drupal install (www.site.local).
1 Let’s add the new subdomain folder inside of C:/Program Files/xampp/htdocs/www.site.local/sites and call it "blog.site.local" (see screengrab below).

The new "blog.site.local" folder will contain all the settings, themes and modules that are specific to the new subdomain, any modules or themes common to all sites should go in you sites/all folder.
Find out more about installing modules and themes.
2 Now we need to create a new settings.php file for Drupal to recognize that the blog.site.local is a subdomain of the main www.site.local domain.
To do this follow the following steps:
A) Copy the settings.php file from www.site.local/sites/default to the folder blog.site.local
A) Copy the settings.php file from www.site.local/sites/default to the folder blog.site.local

B) Now we need to decide if we want our subdomains to share the same database or to have a different database for each subdomains (a Drupal multisite setup).
I will explain how to set up both. Let’s start with a single database for each subdomain:
Single Database Set up
1 Open the settings.php in our new "blog.site.local" folder and modify the $db_url and $db_prefix to reflect our database settings.
Let’s replaced the line below with our database, username and password:
1 Open the settings.php in our new "blog.site.local" folder and modify the $db_url and $db_prefix to reflect our database settings.
Let’s replaced the line below with our database, username and password:
<?php
//$db_url = 'mysql://username:password@localhost/databasename';
$db_url = 'mysql://drupal:drupal@localhost/drupal_db';
?>2 Now we need to alter the $db_prefix variable so that all our database tables for this subdomain are preffixed with some text so we can distinguish between them and the main domain tables.
You can choose any prefix you want for your $db_prefix configuration, I'll use 'blog1_':
<?php
$db_prefix = 'blog1_';
?>And that is it!! Here you have a drupal site with subdomains using a single database!!!
Now just point your site to: www.blog.site.local and proceed with your installation. Each subdomain will have our own database.
Set up Multiple databases
Follow the exactly the same proceedure as with the sinle database set up but make sure you leave the $db_prefix blank:
Follow the exactly the same proceedure as with the sinle database set up but make sure you leave the $db_prefix blank:
<?php
$db_prefix = '';
?>And that is it!! Here you have a drupal site with subdomains using a multiple database!!!
Now just point your site to: www.blog.site.local and proceed with your installation. Your subdomain will share the same database.
I hope this tutorial is helpful!!! Thank you for reading!!
Ariene Ellefsen
http://www.ellewebdesign.com
Comments (12)
Login or register to post comments
Some really great SEO tips
By Imafilmmaker on Monday, May 11, 2009Some really great SEO tips about subdomains! Many people overlook the importance of using keywords in the URL. Thanks so much for this tutorial. Do you know how to do this using MAMP on OSX? I'm not sure I understand how to access the DNS on a mac.
I use this to manage my
By erclerico on Wednesday, May 20, 2009I use this to manage my local hosts on my Mac - very handy for off-line development: http://www.northernsoftworks.com/hostal.html
Really a fantastic tutorial
By nazar2k2 on Friday, September 18, 2009Really a fantastic tutorial for creating the sub domains.thanks for this great tutorial.Also can you please tell me how to do this using Lamp on OS?
Thanks
Thank you for this great
By Program on Friday, November 20, 2009Thank you for this great info, I was struggling to write a subdomains for very long, eventually i got idea here.
fat burning furnace
This is a great tutorial. I
By JulesDM on Sunday, December 6, 2009This is a great tutorial. I was having some issues with this when setting up a subdomain. It turns out the issue was with my GoDaddy account. I finally got my subdomain resolved, but this tutorial is still helpful nonetheless.
This tutorial has give me
By Furnace on Thursday, December 10, 2009This tutorial has give me clear instruction on set up subdomains on my website using Drupal and a few server tricks. -- fat burning furnace and fatburningfurnace review
The new "blog.site.local"
By Select on Wednesday, December 30, 2009The new "blog.site.local" folder will contain all the settings, themes and modules that are specific to the new subdomain, any modules or themes common to all sites should go in you sites/all folder.
jump higher and Mp3 rocket pro
Thank you for another great
By Nathanial on Sunday, January 3, 2010Thank you for another great article. Where else could anyone get that kind of information in such a perfect way of writing? I have a presentation next week, and I am on the look for such information.
Great!! We already have two
By deff_lepp on Wednesday, February 3, 2010Great!! We already have two subdomains but to make it works we need to create a folder inside of our apache installation.
Wrinkle Cream Reviews||Lifecell Cream
I havent tried drupal before
By Boffman on Thursday, February 18, 2010I havent tried drupal before but now i feel like trying drupal... lets see how it would feel.. thanks for the tut of Pure Acai Berry
WiredTree.com Coupons. I
By jackb on Monday, February 22, 2010WiredTree.com Coupons. I needed a new server, and I already had a Wiredtree VPS which I was 100% satisfied with. I decided I’d try out a huge package from Wiredtree! I needed something big for the website I was running that was getting thousands of hits a day. I used this WiredTree.com Coupons and it saved me over $300 dollars a month on the total offer. Wicked!
That's a very useful plugin,
By royalt on Sunday, March 14, 2010That's a very useful plugin, I'm gonna use it on my Drupal site.
online games
dress up games for girls





Delicious
Digg
StumbleUpon
Facebook
Google
Yahoo
Technorati


















