Drupal Tutorials

Drupal Sub domain configuration

You should be comfortable with server configurations and will to get your hands dirty (a bit).

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:

  1. Google treats a sub domain as a totally different website from its main domain
  2. You can use any keyword(s) as a subdomain
  3. 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

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.
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:

DSN setup

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>

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.

Drupal Files

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

Install Drupal

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).

Sites Folder structure

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

Subdomainn settings file

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:
<?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:
<?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

Commenting on this Tutorial is closed.

Categories:

Comments (32)

Pure Solutions Internet Marketing's picture

Some 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 local hosts on my Mac – very handy for off-line development: http://www.northernsoftworks.com/hostal.html

Your exactly right Ima, it’s also important that you to make the url keyword rich also like example putting the keyword lets say pool cleaners you can insert this keyword like this www.domain.com/poolcleaners or www.domain.com/pool-cleaners but for me this is more effective; www.domain.com/pool_cleaners
:)

adodis technology's picture

Really 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

http://www.drupal-web-developers.com

Thank you for this great info, I was struggling to write a subdomains for very long, eventually i got idea here.
fat burning furnace

Superb tutorial and you are right it is important to get the keyword in the url. Thanks again andrew reynolds from debt solutions you guys are my favourite drupal resource!

This 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.

automatically creates subdomains for your site and assigns nodes to those subdomains.Website Placement

Thank you editors for the topic.Its include a lot of useful informations. i join this blog i couldnt see unnecessary arguments and it makes us happy thnx all moderator n editors. Wedding cards

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.
jump higher and Mp3 rocket pro

I really like your website and daily watch it for latest articles because you provides many knowledge about many things.
tramadol online
buy tramadol
tramadol

I 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

I was having some issues with this when setting up a subdomain. Now it is resolved. Thanks!
watch tv online

WiredTree.com Coupons. I needed a new server, and I already had a Wiredtree VPS which I was 100% sat­is­fied with. I decided I’d try out a huge pack­age from Wiredtree! I needed some­thing big for the web­site I was run­ning that was get­ting thou­sands of hits a day. I used this WiredTree.com Coupons and it saved me over $300 dol­lars a month on the total offer. Wicked!

royalt's picture

That’s a very useful plugin, I’m gonna use it on my Drupal site.
online games
dress up games for girls

The amount of insurance contribution is determined by several criteria like the region,the type of car or the personal way of driving.
Regards,
auto insurance quotes

Great tutorial. Drupal rocks and with tips like these … Rock on!

Strength training tips

getbrowser's picture

Great tips indeed. I am ready to build a site with Drupal and this guide is really useful to me. Thanks very much.

life cares

Place a new yoursubdomain.youdomain.com directory in the sites/ directory. This contains a settings.php file configured for this site, and optionally custom themes and modules for the subdmain site.
Buy domain name

nice to be here..

Drupal is competating now with Wordpress.. I like Drupal though.. Just like Resveratrol Supplements

Subdomain automatically creates subdomains for your site and assigns nodes to those subdomains.
shopping cart software

i never seen tutorial like there before, very gr8 tutorial, thx 4 share it.
Canon printer ink

the Drupal sub domain configuration tutorial with images looked amazing. almost removed all of my doubts… Just like Free Energy Generator
Free Energy Generator Plans

syam's picture

Great help works good for me, but still there is some bugs…
Please help me..

Best of luck and congratulations.I have checked your site and I invite others please check it because the information that is available in your site can spell bound any one.and the images that you have shown in this site also very attractive. There is one more site that I have visited, provide me information that is really unique and the service that they offer also I have experienced 1z0-032 dumps, really I enjoy this service mcse courses so I request others please visit this and I want to tell you that after enjoying this service you’ll enjoy it again and again its .

We can assign our subdomains to share the same database or to have a different database for each subdomains a drupal multisite setup.
development

thanks for helping me out with this stuff… LED Emergency Lights

You can read more on it here. http://drupal.org/node/43816

I did this the same way you do any multisite configuration. That is
A) Make sure http://yoursubdomain.yourdomain.com resolves to your nameserver’s public html directory
B) place a new yoursubdomain.youdomain.com directory in the sites/ directory. This contains a settings.php file configured for this site, and optionally custom themes and modules for the subdmain site.

Also, check out the install instructions that come with drupal. It outlines there how drupal looks at a URL and decides which sites/directory to use.

Sam Tresler,
Car Rental Locations

Established domains with a credible web presence and the age factor undoubtedly improve the SEO ranking capability with the search engines and allow the visitors to find the most trustworthy site easily.

web development india, seo training, Web designing

.I have checked your site and I invite others please check it because the information that is available in your site can spell bound any one.and the images that you have shown in this site also very attractive.Atlantis Hotel

I have been lookign for Drupal Sub domain configuration, I was finding in google for last 2 weeks and i got this site very informative. Logo Design