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.
- Must have a webhosting server with access to your cPanel.
- Must have a domain already linked to your webhosting.
- 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:
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:
Hit create button to finish the setup of creating your Subdomain.
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:
Then we need to go to our Subdomain’s Root Document directory and create a new File and name it “index.html” like so:
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:
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:
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.
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!