How can I test the site on my hosting without pointing the domain name to it? (Hosts file - Mac)

How can I test the site on my hosting without pointing the domain name to it? (Hosts file - Mac)

You have probably asked yourself: How can I test my new website while keeping the old website online?

You can do that easily if you edit your HOSTS file.

Normally, when you enter a domain name in your browser, it will look for the name servers of that domain name to learn where your website is hosted. You can indicate that in the HOSTS file, preventing the browser from doing that check.

That way, even if the domain name is not registered yet, and has no name servers, or its name servers are incorrect because it is expired, or for any other reason, you can still visualize it from your browser.

This tutorial only applies for Mac users. Click on the link If you would like to edit your HOSTS file in Windows

  1. Open your HOSTS file in admin mode.

    1. Open Terminal and execute:

      sudo nano /etc/hosts

      Terminal

      nano

    2. You might have to enter your computer password.

      password

  2. Edit your HOSTS file. For each domain name you need a single line, which consists of the IP followed by all hosts you want to direct to that IP address, divided by a single space. Check the example bellow:

    xxx.xxx.xxx.xxx ninefortwo.be www.ninefortwo.be ssh.ninefortwo.be

    hostsline

  3. Save

    1. Press CTRL+o to start saving your change.

      Save

    2. The system will ask you to choose a name for your file. You need to preserve the name! To do that, just press Enter. The system will show you the number of saved lines.

      Saved

    3. Exit with ctrl+x to go back to the command screen.

      Exit

  4. Test