It often helps to have a test environment for working with deployments and for playing around with any changes you want to make to a live site. While most hosting accounts have some form of recovery in case something goes wrong, there’s no substitute for proper testing. Making live changes may save you time and effort but the few times when something goes wrong is enough to teach you the importance of testing. There are many ways to achieve a throwaway environment. Subdomains and subdirectories are two easy solutions. The former however looks more professional and can serve other purposes as well.
For example, using WHM you can create a subdomain to provision a test cPanel account. You can also use subdomains to give to customers who haven’t yet bought a proper domain name for themselves. From special FTP directories and web disks, to creating special CDNs for media and static files, subdomains are an important tool in a webmaster’s repertoire. Let’s look at how to create a subdomain and provision space for it using the cPanel interface.
Creating the Subdirectory
Once you login to your cPanel account, It easy to locate the subdomain creation and management tool. Scroll down to the “Domains” section and look for the “Subdomains” icon as shown below.
From here, we can create new subdomains as well as manage the ones we have. Creating a subdomain requires three pieces of information:
- The Subdomain name
- The Server Name
- The Root Directory
The first is simply the primary name you wish to give to your subdomain. In my test example, I’ve chosen to use “anothertest”. For the second piece of information, you need to choose which domain you want to use. If you have just one domain name attached to your cPanel account, then that is the default. Finally, you have to decide what the document root is going to be.
The last piece of information can be a bit tricky. It’s possible to designate a special location in your hosting account for all subdomains. In this example, we set up a folder called “subdomains” that in turn contains all the folders for the various subdirectories. Since the name of our new subdomain is “anothertest”, we create a new folder within the “subdomains” directory located at the root as shown below:
We’re almost done. Now we only have to include a default “index.html” file that will serve as the starting page for anyone who visits “anothertest.xyz.com”.
Setting up the New Subdomain
Since the purpose of this example is merely to demonstrate how to get up and running with a sub directory, and going to use a skeleton welcome page with basic HTML as shown here:
<html> <head> <title>Sample Index page</title> </head> <body bgcolor=white> <h1>Sample "Index page</h1> <p>This is the sample homepage for the Skeleton directory</p>
And now I only need to package all of this into an index.html file and upload it via FTP to the new “anothertest” subdomain directory we just created.
In the absence of any other files, the server will automatically pick up the index.html resource and send it to the user when they access the subdomain directly.
Since the “subdomains” directory is located in the root at the same level as “public_html”, you will not be able to access it via the traditional folder structure in the address bar. There are many possible configurations, and this is just one way to go about it. In the next article, we look at how to assign subdomains to new cPanel configurations using WHM so that you can quickly give your users a shared hosting environment as soon as possible.