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:
- You have an existing linux cpanel hosting (shared/dedicated).
- You have hosted your nodejs application on some other hosting provider such as heroku/clever-cloud.
- You want the contents should be served from the nodejs hosting.
- You want the email accounts which you have been using should work as it is.
- You have an existing domain name registered say via Godaddy, example: www.mydomainname.com
- Your nodejs application has a domain say mynodewebsite.herokuapp.com
- 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:
- 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
- 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:
- Goto your dashboard.
- Click on the application which you want to add custom domain.
- Click on settings on top right.
- Scroll down a bit, Click on Edit in the Custom Domain.
- Add both mydomainname.com and www.mydomainname.com over there
- 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?
- The ip address of the nodejs hosting website on which it resides.
- 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:
- Log into your Cpanel hosting, usually via cpanel.mydomainname.com by providing login credentials.
- Scroll down till you find heading as DOMAINS.
- Click on Advance DNS Zone Editor.
- Select the domain name from the drop down over there.
- Scroll down to the Zone File Records.
- Now you have to change 2 things over here, the Type A record and the cname record for your main domain.
- Click on edit in the row where its shows your main domain eg: mydomainname.com.
- You will have to change the ip address listed over there with the one which you just copied for your nodejs hosting.
- Save the record and scroll down where it says www.mydomainname.com .
- 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 🙂