Apache2 on Ubuntu Server Commend line to create Sub Domain

Almost every website uses subdomains, my website as well for example. When you enter “http://daanlenaerts.com” in the address bar of your browser, you will get to my website. And when you type “http://blog.daanlenaerts.com“, you will be redirected to my blog, where you’re currently reading this article.

Before you get started, make sure that your subdomain is pointed towards your server. For more information about domain names, read my article about free domain names here.

In this tutorial I’m going to create the following subdomain: “sub.test1daan.tk”. I got that domain name setup in a different tutorial.

Read my article about setting up domains on Ubuntu Server here.

To start with the configuration, sign in on your Ubuntu machine and create a folder which will be used for the subdomain. for me it’ll look like this:

You might have to enter your password to continue.

The folder is created, time to create an index file, so we know we’re on the right track when we visit the subdomain.

Add the following content to the file:

Save the document by pressing ctrl + XY and enter.

We’re also going to set some permissions for the sub folder, so the contents can be accessed by other users.

Now it’s time to create a new virtual host file, to map the subdomain to the right folder.

We’ve copied the original, default, configuration file to “sub.test1daan.tk.conf”. Let’s open the configurations file.

The file should look like this:


Now edit the following properties, and save the document by pressing ctrl + XY and enter.

Save the file by pressing ctrl + XY and enter. The only thing we have to do after this is enable the new virtual hosts and restart the apache2 service.

The configuration of the subdomain is done. You can visit the subdomain in your favorite browser, and you’ll see this:


Leave a Reply

Your email address will not be published. Required fields are marked *

Show Buttons
Hide Buttons
Social Media Auto Publish Powered By : XYZScripts.com