Editing Local Hosts File on a Mac

Editing Local Hosts File on a Mac

A good cheat for viewing a website before it is live on a server is to add an entry to your Host file on your Mac. This file bypasses the DNS so you can view the site whilst it's still in development.

On MAC OSX

1. Open Terminal from Applications>Utilities>Terminal.

2. Open the hosts file in Terminal by entering:

$ sudo nano /private/etc/hosts

(you may need to remove the '$' if terminal reports "-bash: $: command not found").

3. Enter your Mac password if you have one.

4. Use the arrow keys to navigate to the bottom of the list, and enter the IP Address of your server, hit the tab button, then input the url of your website.

5. When finished, hit Control+O followed by ENTER/RETURN to save changes

6. Now you can test your sites as if they were live. You may need to clear your browser cache and then browse to the domain.

Note: To go back to using the public DNS you need to revert the changes made to your local host file. To do this, do the exact same steps above, but remove the new entries you made, then save as detailed in step 5. You may need to clear your browser cache once again not ensure everything is fresh.

NB: If you entered www.example.com in your host file, you'll need to browse to www.example.com.
Example.com would still show the current live site unless you also place this in the hosts file.