Tuesday, 9 June 2015

Creating sub-domain in Apache2, Ubuntu 14.04

It is quite simple to add a sub-domain to an existing ubuntu hosting account. You just have to follow few simple steps:-

Step 1 : Go to your domain provider and then login to your account.(For example, let's suppose I'm having godaddy account.)

Step 2 : Click on domains, and then choose a domain for which you want to add a subdomain.

Step 3: Now, click on DNS File Zone, then click on add record and then select record type: A (Host), Host: your sub-domain, points to: your IP Address and TTL: any option from dropdown.

Step 4 : Finally, click on finish and save.

Now, you have to move on second part i.e. the ubuntu hosting account which you want to access through this sub-domain.

Step 1: Login to your hosting account and type the following command to access  000-default.conf.
nano /etc/apache2/sites-available/000-default.conf

Step 2:  Add this piece of code in this apache default configuration file:-
<VirtualHost *:80>
ServerAdmin webmaster@example.com
ServerName blog.example.com
ErrorLog $(APACHE_LOG_DIR)/error.log
CustomLog $(APACHE_LOG_DIR)/access.log combined

Here is the snapshot:-

Step 3: To save this file press CTRL+X, then Y and then ENTER.

Step 4: After that, you have to restart your apache server. To do this, type following command:
service apache2 restart

All done! You have successfully added a subdomain to your existing ubuntu hosting account...