When you’re developing locally, whether you’re using MAMP, XAMP or Vagrant, at some point you might need to give a special name to your local development environment.
Because why not?
I mean it’s totally okay to go to http://192.168.33.10 but why not make it http://mijimo.local or http://www.mijimo.dev
To do that, we need to edit our hosts file on our Mac.
It’s a pretty easy and straightforward task. Here’s how to do it.
Editing your hosts file on a Mac
Step 1:
Open your Mac’s Terminal (by the way, if you’re into trying something new I suggest iTerm2)
Step 2:
Edit your hosts file. It’s located at /private/etc/hosts
In your Terminal window enter the command below
sudo nano /private/etc/hosts
sudo lets you act as the root user, so you’ll be asked to enter root account’s password. Next, nano is a text editor working in your Terminal window, that’s the program we use to edit our hosts file.
Step 3:
Add the following line to the end of the file (also modify according to your likes)
192.168.33.10 mijimo.local www.mijimo.com
This tells your Mac to directly go to the given IP address without hesitation, when you enter the URL http://mijimo.local or http://www.mijimo.local
Step 4:
Press Control-x, you’ll be prompted to save the changes and exit.
Step 5:
In some cases, you may need to flush your Mac’s DNS cache.
To accomplish this you need to enter the code below:
sudo dscacheutil -flushcache