Subdomains

Fill in the blank

The protocol

What protocol should your websites use?

Your answer:
Saving
Not graded. So why do it?

Lesson topics

What's a subdomain?

You have a domain, like silverthoughts.org. But you want to have a bunch of websites on it. Can you do that?

Yes! Subdomains can help. A subdomain is an extended name, based on your domain name, that acts like a separate website.

Take the site you're looking at now. It's at learnweb.skilling.us. That's a subdomain. The name has three parts: learnweb.skilling.us

The domain is skilling.us. I had to pay for that. Go to skilling.us, and you see the main website for the Skilling project.

This website is a subproject, that's part of Skilling. I made the subdomain learnweb, and put the files for this website there. It's a separate website from the one at skilling.us.

I didn't have to pay for the subdomain. I can make as many subdomains as I want, without spending a cent. Woohoo!

More, more, MORE!

There's another course website, on Excel VBA programming. That's at vba.skilling.us.

So there are three separate sites:

  • skilling.us: the main project site
  • learnweb.skilling.us: this course
  • vba.skilling.us: a programming course

(Actually, there are more than that.)

They are all separate sites, not connected to each other. I only pay for skilling.us, and can make as many sites as I want.

Subdomains have folders on your servers

Each subdomain has its own folder on your server. That's how the subdomains are kept separate.

Here are the folders for the subdomains above. The ~ is a Linux thing. It stands for my user account's root folder. On Windows, that's C:\Users\username.

Subdomain Server folder
skilling.us ~/public_html
learnweb.skilling.us ~/learnweb.skilling.us
vba.skilling.us ~/vba.skilling.us

The mapping from the domain (skilling.us) to the folder ~/public_html was set up by the hosting company. I didn't change it. The subdomains, I created myself. I could have called the folders anything I wanted (e.g., anything-i-wanted), but I gave the folders the same names as their subdomains, to keep things easy for myself. Easy is good.

Marcus
Marcus

Wait. Can a dot be part of a folder's name?

Yes. In Windows, too. Give it a try. Create a new folder with a dot in its name.

Marcus
Marcus

OK, wait a mo... Hey! It worked!

Your own subdomains

You can have subdomains on your domain, too. For example, you can have one for your final project, and another for your other exercises. Keeping everything separate means that your files won't collide with each other.

You can only create subdomains on domains you own. E.g., you can create final.ragingmonkeys.com only if you registered ragingmonkeys.com. If you registered happygoats.com, you can create:

  • exercises.happygoats.com
  • final.happygoats.com
  • lunacy.happygoats.com
  • pingpong.happygoats.com

You can't create exercises.sadhippos.com, unless you own sadhippos.com.

To see what domains you own, log in to reclaim, and click the Active domains button:

Active domains

You'll see a list of your domains:

Domains list

So, I could create exercises.cryptidkitchen.net, but not exercises.whitehouse.gov.

Making subdomains

Open cPanel. Click the Domains icon on your cPanel home page.

Domains icon

This opens the domain manager.

Click the button Create a new domain.

Type the name of the subdomain you want for your final project, like final.ragingmonkeys.com or final.doggosrule.net.

Here's what I did to make a new subdomain. Note: I own kieranmathieson.com, so I can create subdomains on it.

Subdomain form

cPanel will suggest a name for the Document Root (File System Location). That's where the files for your subdomain will be kept on your server. We'll work on that in the next lesson. Make the root the same as your domain name, to keep things simple, but you can make it something else if you like.

Now make another domain. Call it "exercises". It will be something like exercises.yourdomain.com.

Password protect your exercises domain

You should protect your exercises subdomain. You'll be using it to submit exercises for this course.

In cPanel's file section, there's a Directory Privacy icon.

Directory Privacy icon

Note

"Directory" is another word for "folder." You'll see both words used.

When someone tries to access a file in a private folder, they'll be asked for a username and password.

Remember, a subdomain is a reference to a folder on your server. If you protect the folder, you'll protect the subdomain.

Find the document root for your exercises subdomain. It will be something like exercises.yourdomain.com. Click the Edit button.

Edit a folder's protection

A form will show, that let's you protect the directory.

First, check the password protect box, and type a name for this security entry. Exercises is an easy one. Click Save.

Top part

Click Go Back to return to the configuration.

Then you need to make a user, who can access the folder. That's lower down the page.

Create user

Enter a username and password you can remember. Click save.

I had to mess around a bit before I got it working. You can look at the official documentation if you want.

When someone goes to the subdomain, they'll see something like this:

Challenge

Hooray!

Remember, if you want someone to be able to see your work, you need to give them both the username and the password.

When you submit an exercise, you'll need to tell the grader what the username and password are.

Adela
Adela

Can I change the username and password?

Sure, no problem. Just go to the cPanel screen you just used, and change the info.

The only problem is that the grader might not have graded everything you submitted. Your submissions might have the old username and password. You can edit your submissions, though, those that haven't been graded yet, and add the new password.

What's this "Index of" thing?

I got this question from Anne-Abel:

I am not sure what I am doing wrong here. I created the folders and files per the course instructions, however they are not appearing properly. There's Index of /. I don't understand why it's changing to "index of". Appreciate your help.

A good question! This is what Anne-Abel saw:

Default page-like-thing

This is perfectly normal. Most URLs contain a domain, a list of folders, and a file name, like this:

http://webexamples.skilling.us/pupperware/final/images/dog1.jpg

webexamples.skilling.us is the domain, linked to a server. /pupperware/final/images is a list of folders, just like the C: drive on your PC, but on the server. Into the pupperware folder, then into the final subfolder inside pupperware, then into images. The last bit, dogs.jpg, is the name of the file to show. A dog photo, in this case.

What happens when you leave off the folder and file name? Like this:

http://webexamples.skilling.us

There is no folder or file. Every server is programmed to do something by default when this happens. What it does depends on how the server is programmed. The rules for Reclaim servers, unless you do something special, are:

  • If there's a file called index.html, show that.
  • Otherwise, show a list of the files on the root (top) folder of the server.

That's what Anne-Abel saw. The server showed a list of files in her subdomain.

Try this one: http://webexamples.skilling.us.

GEEK STUFF

If you look at the URL of this page, you won't see a file name. The URL ends in what looks like a folder name, but isn't. Instead, this server has programs that translate URLs into database lookup instructions. The text you're reading now isn't in a page anywhere. It's in a record in a database table.

When the server gets this URL, it looks up the text in the database, processes it in various ways, and sends back the results to your browser. This site explains how to write programs to do this sort of thing.

/GEEK STUFF

Thanks for the question, Anne-Abel. Questions like this help me improve the course.

Exercise

Exercise

Subdomains

Make a screen shot of your subdomains cPanel page, showing at least the subdomains final and exercises (or whatever you called them). It might look something like this:

Subdomains screen

I have 32 subdomains (really!). Yours will be different.

Summary

  • A subdomain adds something to the front of a domain, like rosie.doggos.com.
  • Subdomains act as separate websites.
  • Create as many as you want, from cPanel.
  • cPanel lets you add encryption to your subdomains.
  • cPanel lets you add usernames and passwords to your subdomains.

Up next

Let's see how you mess with files on your server.