Moved the site to production, but the domain shows a different site
Once I ran into strange behavior. After development and successful testing I moved a site to the live server with cPanel. Everything went as it should, with no signs of trouble, but when I opened the live site I was very surprised: it was a completely different site, not mine. Clear the cache and… what is going on? Where is my site?
Problem: The site is in cPanel on the new server, but the browser shows a completely different site.
Solution: It turned out that the DNS record of the domain pointed to another IP address. This happens very often when the domain had an old site: a new site is made on a new server, but the domain still points to the old IP. The real fix is to update the DNS records. If you cannot do that yet, the hosts file lets you see the site on the new server on your own computer.
Check where the domain points
You need two IP addresses: the IP of the new server (in cPanel it is in the right sidebar, under “Shared IP Address”) and the IP the domain resolves to:
ping domain-name.com # or, if ping is blocked nslookup domain-name.com
If the addresses differ, the domain still goes to the old server.
Fix 1. Update the DNS records
Change the A record of the domain (and of www, if it is a separate record) to the IP of the new server, at the registrar or wherever the domain’s DNS is managed. The change takes effect after the TTL of the old record: usually from a few minutes to a few hours, up to 48 hours in the worst case.
Fix 2. The hosts file for testing
To test the site on the new server before DNS is changed, open the hosts file on your computer and add a line with the new server IP and the domain:
100.100.100.100 domain-name.com www.domain-name.com
where 100.100.100.100 is the IP of the new server and domain-name.com is your domain.
The hosts file is here:
- /etc/hosts on Linux and macOS (edit it with
sudo); - C:\Windows\System32\drivers\etc\hosts on Windows (open the editor as Administrator).
Now only your computer opens the domain on the new server, everyone else still sees the old site.
NOTE: If nothing changes after editing hosts, clear the DNS cache: sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder on macOS, ipconfig /flushdns on Windows, and restart the browser. And remember to remove the line when DNS has been updated, otherwise you will not notice if something is wrong with the real records.