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 web.skilling.us
. That's a subdomain. The name has three parts: web.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 web
, 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 a Skilling demo site as well. I wanted that as a separate website. I made the subdomain demo.skilling.us
.
There's another course website, on Excel VBA programming. That's at vba.skilling.us
.
So there are four separate sites:
skilling.us
: the main project siteweb.skilling.us
: this coursevba.skilling.us
: a programming coursedemo.skilling.us
: a demo 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 |
web.skilling.us |
~/web.skilling.us |
vba.skilling.us |
~/vba.skilling.us |
demo.skilling.us |
~/demo.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
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
OK, wait a mo... Hey! It worked!
Making subdomains
You can have subdomains, 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:
Type "final" in the Subdomain field. Hit tab. You'll see something like:
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
.
Securing your subdomains
You're going to add two types of security. First, you want to use HTTPS, to encrypt all traffic to and from your sites. For that, you'll need digital security certificates.
On the cPanel home, click the Let's Encrypt icon under Security. The section Issue a New Certificate will list all the things you can make certificates for. You'll want certificates for three things:
- Your main domain
- Your
final
subdomain - Your
exercises
subdomain
Each one has a "+ Issue" button. Click it.
Leave the settings as-is, and click the Issue button.
That's it! Now all of your sites will be at https. For example:
https://exercises.yourdomain.com
Password protect your exercises
domain
You'll add another form of protection to one of your subdomains, the exercise
one. You'll be using that domain to submit exercises for this course. You don't want other people to be able to copy those files. Remember, freeloaders.
In cPanel's file section, there's a 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.
Choose the document root for your exercises subdomain. It will be something like exercises.yourdomain.com
.
This form is a bit tricky. First, check the password protect box, and type a name for this security entry. Exercises is an easy one. Click Save.
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.
Enter a username and password you can remember.
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:
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
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
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:
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.