One of the primary tasks for a web developer is to set up a development environment that resembles the production environment as much as possible.
When I was a beginner in web development, I used to create a subfolder for each new project in my web server documents root and put all my project files in there; the local address of my projects would look something like this: localhost/myproject/index.php. This approach was very awkward and used to cause many problems during deployment into production environment.
Now, when I start developing a new web project, first thing I do is setting up a local hostname for my project; something like myproject.localhost which maps to a folder separated from other ones.
In this article, I want to show you how you can create hostnames on your local computer. I assume that you use Apache web server. Please note that these hostnames are not necessarily subdomains of localhost. I like to create them like myproject.localhost; you can create something like mywebsite.com.dev or even google.com.
For creating a local hostname, you should do these steps: