If you don’t know how to add a subdomain in cPanel of your Webhosting, then this is the article for you. Often websites are linked with a Content Delivery Network (CDN), for various security and performance reasons, as they should do. It is highly encouraged to link your Webhosting with the CDN, especially since Cloudflare, a CDN provided by Google, offers prominent features completely free. Those features include DNS securityminifying CSS, JavaScript, HTML filescaching website content for a faster response time, free SSL certificate (HTTPS), Web Application Firewall (WAF), and much more. For full detail of its offerings, check out Cloudflare’s official page. 

Going back to the original topic, how to add a subdomain in cPanel of your web hosting, especially when it’s connected to a CDN such as Cloudflare. Before we start there are a few prerequisites before following along this article.  

Prerequisites!

  1. Must have a webhosting server with access to your cPanel. 
  2. Must have a domain already linked to your webhosting. 
  3. Must be familiar with the concept of sub domain and networking. (Not necessarily required but recommended) 

Step 1: Create a Subdomain

So, let’s directly dive into it; open up your webhosting cPanel and go to “subdomains” option as shown in the below picture: 

Opening Subdomain Page in cPanel
Opening Subdomain Page in cPanel

After you have opened the Subdomains page, you will be asked to create one by entering the name of a Subdomain you want to add. You should know that the name you enter here will be a prefix to the actual domain name. In this case I’m making a subdomain with the name “daniyal” so my final URL would be “daniyal.programmatically.com”. One more thing to notice here is the third field called document root. It is the location in your File Manager where your website content would be stored for this subdomain. It is all shown in the image below: 

Creating a Sub Domain
Creating a Sub Domain

Hit create button to finish the setup of creating your Subdomain. 

Sub Domain Created Successfully
Sub Domain Created Successfully

As you can see the sub domain with that URL is now made, and for most of you, you can directly copy paste the URL your browser and see that it is working. but for those who are also connected to a CDN just Cloudflare, there is an additional step you need to perform before getting your site to work. But before even that let us add some HTML file into your document root directory when you open up your sub domain on a browser something properly shows up.  

Step 2: Adding HTML Template in Subdomain Directory

First, we need to go to File Manager option in our cPanel like so: 

Where the File Manager is in cPanel
Where the File Manager is in cPanel

Then we need to go to our Subdomain’s Root Document directory and create a new File and name it “index.html” like so: 

Adding an HTML template in Subdomain directory
Adding an HTML template in Subdomain directory

Inside the “index.html” file we can add any dummy boiler plate HTML template. You can find it on google to, as I have from this site. Moving on, IF you are not connected to a CDN, then the subdomain should already be working for you. Just search the URL on a browser like shown in the image below:

Subdomain URL showing output
Subdomain URL showing output

Step 3: Adding ‘A’ Record in your Cloudflare DNS

So, if your webhosting is connected to Cloudflare end and you want to add a subdomain, then you must add ‘A’ Record in the DNS of Cloudflare. Let us see how we do that. Firstly, login to your Cloudflare account and open DNS tab like the image shown below:  

Adding A Record in Cloudflare DNS tab
Adding A Record in Cloudflare DNS tab

Click on Add record button and enter the name of your subdomain, i.e., ‘daniyal’ in my case. Then insert the Ip address in the Ipv4 address field. Ipv4 address is the one you will find in the “GENERAL INFORMATION” panel on the right side of your cPanel dashboard. Just copy-paste it here and hit save. The image shown below guides you as well.  

Filling in A Record info in Cloudflare
Filling in A Record info in Cloudflare

THATS ALL! 

Now you can simply follow step 2, if you didn’t already add an “index.html” dummy html template. You’ll see the same output.  

That is all folks. I hope you learned exactly how to add a subdomain in cPanel of your webhosting if it is connected to Cloudflare CDN. Please like and commend below and leave your reviews.  

Have a great one!