Subdomain, Dev & Prod Environment in cPanel

Md. Hasnain
4 min readOct 8, 2021

--

You will learn how to create subdomains, setup different environment for your project and access them with separate subdomain.

Step 1: Create separate branch in Git.

We should have separate branch for our project in Git. At least master, development and production branch. Development should be done in separate feature(i.e. feature/login) branches and then merged into development(or dev) branch. Then we should deploy the dev branch to our development environment in the server. If everything is fine, production(or prod) branch should merge with dev branch and then deploy to the production environment.

For now, please create dev and prod branch and push them to your Git repo.

Step 2: Subdomain

2.1 Go to your cPanel and press “Subdomains” under the DOMAINS tab.

2.2 Insert the subdomain name for development environment(i.e. dev). The dev project will be in /public_html/dev/. You can change it if you want. Now click “Create”. This will be used for our dev environment. For prod environment we will use the original domain and File Manager’s root directory(/public_html).

Step 3: Deploy to different environment

If you followed the other articles above, you should have already deployed your project from Git to cPanel. We will use that same project to deploy to our dev and prod environment.

3.1 Open your project and checkout to dev branch. Edit the “DEPLOYPATH” inside .cpanel.yml file. We need to add the root directory of our dev environment(i.e. dev) at the end. The line should look like this:

- export DEPLOYPATH=/home/YOUR_CPANEL_USERNAME/public_html/dev/

The prod branch .cpanel.yml should remain the same. The line inside that should look like this:

- export DEPLOYPATH=/home/YOUR_CPANEL_USERNAME/public_html/

DO NOT forget to commit the changes and push.

3.2 From cPanel select “Git Version Control” under FILES

3.2 Click “Manage” button from the right side of your repository

3.3 Select dev branch from Checked-Out Branch. Click “Update”. Then go to Pull or Deploy tab.

3.4 If necessary click Update from Remote. And finally, click “Deploy HEAD commit”. This will deploy your dev branch code inside /public_html/dev/. If you go to public_html/dev folder you should see the files there. Now you can load your subdomain to test the project.

3.5 Now to deploy the prod environment, go back to Basic information tab. And change the checkout branch to prod. DO NOT forget to click “Update”.

2.4 Go to “Pull or Deploy” tab, and click “Deploy HEAD Commit”. It should deploy your production code into /public_html. And that’s ALL!

If the deployment is failed please check the fix section in PART-2.

Thats all for this article series! I hope you learned something new and deployed your project successfully. If you have any question or suggestion please feel free to add on the comment section. Have a great day! :)

--

--

Md. Hasnain

Programming is my hobby and Android is my passion :) . I am a professional Mobile Application Developer(Native and cross platform).