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!

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

Let's do it.

Note

If you forget how to make a subdomain, come back here for a reminder.

Click the Subdomains icon on your cPanel home page. You'll see:

Subdomain form

Type "final" in the Subdomain field. Hit tab. You'll see something like:

Creating a subdomain

The Document Root is the folder where the files for your subdomain will be kept. We'll work on that in the next lesson.

Now make another domain. Call it "exercises". Note the document root. 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.

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.