Jsaddicts

Create Sub Domain In Single 3 Steps

552 Views

Hello Buddies

This article helps you to create subdomains on DigitalOcean in a few simple steps.

So let’s go to create a simple subdomain.

Step 1: Create a new A Records

 Go to the networking section if you are using DigitalOcean else go to your DNS management console.

 Let’s create a new A Record with hostname being ex. blog or eCommerce. Where redirect to is the IP address i.e. basically the IP address of the droplet.

Step 2: Create subdirectory & host project files

Create a directory under /var/www/ directory using the commands

cd /var/www/

mkdir subdomain

cd subdomain

sudo nano index.html

When you are inside the index.html file, write anything ex: “Subdomain Working”

Step 3: Configure Virtual Host

 Now let’s configure the apche2 virtual host, which will allow our domains to refer to a project directory.

Type in the following commands

cd /etc/apache2/sites-available/

cp 000-default.conf subdomain.website.conf

nano subdomain.website.conf

Now once you are inside the config file, change the following

#ServerName

#ServerAlias

#DocumentRoot

Here, the ServerName is the domain that you want – say eCommerce.mysite.in, ServerAlias is another name using which you want to refer this domain any CNAME in most cases. DocumentRoot is where your project files are located (Root directory of your project)

Point DocumentRoot to the directory where your project files are located.

ServerName subdomain.website.com

ServerAlias www.subdomain.website.com

Save the file Then Run these two commands

  1. a2ensite subdomain.website.com
  2. sudo service apache2 restart

Boom, now you can try to access your subdomain.

Mani Sh

author

2 comments on "Create Sub Domain In Single 3 Steps"

Leave a Reply

Your email address will not be published.