When building websites, you may need to work on a site before it is visible to the rest of the web. You buy the hosting before pointing the domain to it, and start working on it by viewing it on your own computer, changing a few parameters in the hosts file.
To edit the hosts file on Mac OS X, type the following commands in Terminal:
To edit the hosts file you need to use the “NANO” editor, which you can launch from Terminal.
- Type the command:
sudo nano /private/etc/hosts - Enter your password
- Make your changes at the bottom of the text (e.g. 127.0.0.1 www.mywebsite.com)
- Press
CTRL + Oto save - Press
CTRL + Xto exit
Use the arrow keys to move the cursor to the end of the file and enter data such as 182.12.37.123 www.mywebsite.com mywebsite.com. This way, when you open the address in your browser, the site you are building will appear just like any other site, without actually being published on the web, because the request is not forwarded to the DNS server: your Mac resolves the name directly from the hosts file.
Enjoy!
