PHP to Node.JS Migration – Retaining Your Cpanel E-Mail Account While DNS Migration

Hello folks,

If you are here on this blog, you might be searching for the ways to migrate your existing PHP website to Node.js.

In this blog i will try to explain, how you can point your existing domain to nodejs hosting and keep using the cpanel hosting for managing emails for your domain.

To start with, you will have to make sure of the following things:

  1. You have an existing linux cpanel hosting (shared/dedicated).
  2. You have hosted your nodejs application on some other hosting provider such as heroku/clever-cloud.
  3. You want the contents should be served from the nodejs hosting.
  4. You want the email accounts which you have been using should work as it is.
  5. You have an existing domain name registered say via Godaddy, example: www.mydomainname.com
  6. Your nodejs application has a domain say mynodewebsite.herokuapp.com
  7. Your Name Server for www.mydomainname.com points to your existing cpanel hosting say ns1.cpanelhosting.com

So now you want that www.mydomainname.com should point to heroku server i.e. mynodewebsite.herokuapp.com

Work to be done:

  1. Add your domain name in the alias of your project in nodejs hosting , i.e. add www.mydomainname.com as alias in your heroku account for the mynodewebsite.herokuapp.com
  2. The DNS of www.mydomainname.com will have to be changed from your cpanel hosting (not from your domain registrar eg: godaddy)
Steps to follow:

For the first part i.e. adding custom domain to your nodejs app, steps are really easy.

For Heroku hosting:
  1. Goto your dashboard.
  2. Click on the application which you want to add custom domain.
  3. Click on settings on top right.
  4. Scroll down a bit, Click on Edit in the Custom Domain.
  5. Add both mydomainname.com and www.mydomainname.com over there
  6. Click on Save, Thats It!

For the Second Part which is a little tricky but still easy to do.

What do you need for this?
  1. The ip address of the nodejs hosting website on which it resides.
  2. Your main domain name.

To get the ip address of your nodejs hosting, try to ping it from your console/command prompt.

Alternatively you can take the help of websites which would give you the ip address of any website, for eg https://www.site24x7.com/find-ip-address-of-web-site.html

Just put in the url of your nodejs app url say mynodewebsite.herokuapp.com and it will show you the ip address of it. Copy that ip address to clipboard!

Steps to change your current DNS for main domain:

  1. Log into your Cpanel hosting, usually via cpanel.mydomainname.com by providing login credentials.
  2. Scroll down till you find heading as DOMAINS.
  3. Click on Advance DNS Zone Editor.
  4. Select the domain name from the drop down over there.
  5. Scroll down to the Zone File Records.
  6. Now you have to change 2 things over here, the Type A record and the cname record for your main domain.
  7. Click on edit in the row where its shows your main domain eg: mydomainname.com.
  8. You will have to change the ip address listed over there with the one which you just copied for your nodejs hosting.
  9. Save the record and scroll down where it says www.mydomainname.com .
  10. You will have to change it CNAME for this record from www.mydomainname.com to mynodewebsite.herokuapp.com

Tada!!! you are done.

Now whenever you will open www.mydomainname.com it will point to your herokuapp hosting and the fun part is that your email/ftp account for your existing cpanel will not get affected from this migration :)
FOUND THIS USEFUL? SHARE IT

Leave a comment -