March 18, 2011

Using The Hosts File Test Your Magento Site
We often have clients that set-up a staging environment in addition to their production e-commerce environment. We also do a lot of website moves for clients who want to see their site on our servers before the final cut-over takes place. While many web applications are domain agnostic Magento is finicky about being run under the domain its configured with. To complicate things the domain may be used by add-ons or extensions that require the “live” domain to be used.
The simple trick we often use to make the development and/or newly moved site look like they are running under the final domain is to use the hosts file. To understand the hosts file you need to understand some basics about how the Internet works. The Internet uses IP addresses to denote a location, like your web store or your home computer. Instead of having to converse using IP addresses, which can be hard to remember (and with IPv6 impossible to remember) the Internet uses the Domain Name System (DNS). DNS has the simple job of translating names (like to IP addresses. When you type into your browser it uses your operating system’s networking subsystem to do the DNS translation from name to IP.

Once nice feature of operating systems (Linux, Mac OS, etc) is that they allow you to short-circuit this DNS process and provide your own values for any name. For instance, you could change the IP of locally to point to This change would be local to your machine only and not visible to anyone else. This comes in handy when you know the IP address of your new Magento store (or any other site) and want to see that site under your domain without making this change global. It’s as simple as this:
On Linux (or Mac OS) just edit the file (as the root user) named /etc/hosts (If you’re on Windows the hosts file lives in C:\windows\system32\drivers\etc\hosts). The file has a simple format of 2 columns. The first column is the IP address that you’d like the name to resolve to and the 2nd column is the name itself. So, if I wanted to point to go to the IP I’d just edit the /etc/hosts file and add the following line at the bottom:
Now when I go to in my browser (or using any other networking function on the system) it will think that is the actual IP address. Don’t remove any entries from the file unless you added them. Removing standard lines from the file can have unintended side-effects.
Now you can test your site as if it were live and make sure any features of the site that require the “real” domain work correctly. REMEMBER to change the hosts file back so you don’t inadvertently make changes to the test area thinking it’s the live area. You’ll be pulling your hair out wondering why your friends on other computers don’t see your edits.


Nexcess, the premium hosting provider for WordPress, WooCommerce, and Magento, is optimized for your hosting needs. Nexcess provides a managed hosting infrastructure, curated tools, and a team of experts that make it easy to build, manage, and grow your business online. Serving SMBs and the designers, developers, and agencies who create for them, Nexcess has provided fully managed, high-performance cloud solutions for more than 22 years.

We use cookies to understand how you interact with our site, to personalize and streamline your experience, and to tailor advertising. By continuing to use our site, you accept our use of cookies and accept our Privacy Policy.