This guide shows how to modify hosts file in Mac OSX computer.
Benefits of Changing Hosts File
Modifying the hosts file can be a useful tool for web developers. By changing the hosts file, developers have a method of previewing or testing a domain on their server without actually changing that domain's global DNS over to Rad Web Hosting's network. Typically, this type of functionality is gained through using Apache's mod_userdir, but this is actually a highly ineffective approach for serious development and testing.
The reason the above method is ineffective is due to the well-documented compatibility issues between Apache's mod_userdir and mod_rewrite. Often, in order to properly test an application, the application's URL will need to be changed to the mod_userdir temporary URL (http://example.com/~fred), which can cause unexpected and unnecessary complications.
The preferred alternative is modify your local hosts file. By modifying your hosts file properly, you can point your domain to a specific IP address (i.e. the one assigned to your Rad Web Hosting hosting account) without having to defer to your router/network or on an external DNS resolver to inform your machine of the IP address of your domain. This means that if you make your modifications correctly, you can view your website in your browser, using your normal domain name, without actually affecting the global DNS of your domain whatsoever!
Edit Hosts File in Mac OSX
The easiest way to make modifications to the host file on OSX is via the Terminal. To open your terminal, you will want to perform the following:
1. Click the Spotlight icon in the top-right of your desktop (magnifying glass)
2. Type: terminal
3. Press: Enter
If you completed the first two steps, you should now see this in the upper right-hand corner of your screen:
Select "Terminal" and press "Enter." You will now want to execute the following command to open your hosts file with the nano text editor:
sudo nano /private/etc/hosts
An example can be seen below:
You will be prompted for your password (the same one you use to login to your Desktop). Identical to the Windows host file, you simply add your IP address and domain, as pictured below:
To save your changes:
-
Press CTRL+X
-
Press "y"