Apache's mod_userdir module has traditionally been the preferred way to check if sites are working properly on a machine without DNS being configured. This allows you to confirm that a site is functional before DNS is pointed to that system, and allows you to test the site before it goes live.
However, mod_userdir is no longer the best option for testing websites, due to issues with absolute links and the new PHP handlers.
With the rise of Search Engine Optimization (SEO) and content-scraping, developers are now using absolute paths for all site content. This makes it impossible to test a site with mod_userdir; although the homepage of the site works, any subsequent links you click on reference the full URL via the active DNS record, and take you to the live site.
In addition, EasyApache 4 provides greater control over the PHP configurations on your system and also includes two new PHP handlers that do not work with mod_userdir, PHP-FPM and CGI.
The best way to test sites under these conditions is to edit your local computer's hosts file. While this does take a bit more effort at the user-level than just entering a different URL into the browser, editing your local hosts file to preview sites often results in a better experience and may be the only option available if you're running one of the PHP handlers that does not support mod_userdir. Editing your local computer's hosts file is a way to trick your computer into thinking a website is hosted on a different machine than it really is by directing the DNS to a different location for a specific domain. This is something that can be configured quickly on any operating system, including Windows, MacOS, and Linux.
How to Edit the Local Hosts File
In these examples, you point an imaginary website, cpanel.rocks, to a test IP address of 192.0.2.1.
It's important to note that, no matter which version of Windows you're working with, you must have administrator access on the machine in order to change the file.
On Windows systems, the hosts file is located in
C:\windows\system32\drivers\etc\hosts. You can either navigate directly to that file through Windows Explorer, or you can enter this text in the search box when you click the Windows icon to open the hosts file in Notepad:
Add this line of text to the bottom of the file:
Save the file, restart your browser, and verify that your site now points to the new location.
Windows 8, 8.1, and 10
In Windows 8 and 10, open the Notepad app as an administrator. To do this, search for the application, then right-click, and choose the "Run as Administrator" option.
Once Notepad is running, click File, then Open, then enter the following line into the "File name" box:
Now edit the file normally and add this line of text to the end of the file:
Save the file and restart your browser, and now you can view the site via its new IP address.
The easiest way to perform this work in MacOS is to access the file using terminal. Run this command to open your hosts file (Note that this example uses the Vim text editor, but you can use any editor you like):
sudo vim /etc/hosts
This opens the hosts file on your system. At the bottom of the file, add this line to point the site to the new IP address:
Once you've added that line, save the file. Restart any browsers you're using to make sure the change is loaded.
The process of editing the hosts file in Linux is nearly identical to the MacOS process, although you may not see those commented lines at the top.
Just as in MacOS, open this file as an administrator with your favorite text editor, add the line to the bottom of the file, save the file, and restart your browser to load the changes.