Menu
In my hosts file, I have an entry '127.0.0.1 domain dev'. If something comes in port 80 requesting domain.dev, the hosts site causes it to be directed to the local computer, and Apache, listening on port 80, uses /users/me/sites/whatever as that site's root and sends the to the browser. Nov 30, 2014 By default, the Apache Virtual Host configuration on Mac OS X is located in a single file: /etc/apache2/extra/httpd-vhosts.conf. You need to edit the Apache configuration to include this file and enable virtual hosts. Over the years, I have created many.
Setting up Virtual Hosts in Apache on on macOS High Sierra and OSX is straight forward after you have your local Web Development environment up and running – get your web development up and running first including Apache, PHP and MySQL on macOS following this macOS High Sierra Apache/PHP/MySQL guide here if required.
The process of setting up Virtual Hosts is done easier in the Terminal either using nano or vi with sudo or as a root user, or you can you a GUI visual editor like BBEdit which allows access to the /private/etc directory by clicking ‘Show Everything” in the open dialog box.
Allow the vhosts configuration from the Apache configuration file httpd.conf
![Mvps hosts Mvps hosts](/uploads/1/2/6/6/126616739/804748754.png)
Open the httpd.conf
Search for ‘vhosts‘ and uncomment the include line
Edit the vhosts.conf file
Open this file to add in the virtual host.
An example domain in the file is given of the format required to add in additional domains, just follow this to create your new virtual host:
We can take this example and extend on it, if you wanted a domain named apple.com for example, you can copy the existing text block and edit to suit:
So in the example above a vhost for apple.com is created and the document root is in the Sites folder, in the text block above I have also added in some log files, what you need to change is the document root location username and domain name to suit your needs. Finish and save the file.
Now also you need to map the IP address to be the localhost.
Map Your IP address to localhost
Add the Domain and ‘www‘ alias to resolve to the localhost address
Restart Apache
Check out your local vhost domain in the browser
Losing Localhost
One caveat to note about virtual hosts is that once set up you lose your older document root previously at /Library/WebServer/Documents or accessed in the browser at http://localhost what happens is that you get a 403 Forbidden Error. But the ~/username document root is still compatible.
To get around this, you need to add in a vhost for localhost and declare this vhost before any of the others, in the same file:
Add in:
Restart Apache
Changing the WebServer Default User
One of the frustrations of using the Users/username/Sites folder for vhosts is the permissions issues with things like updates and authentication.
This is because the default webserver user which runs httpd is known as _www, which will not be the user in your local account. If your machine is only in use by you and the webserver will run only under your account then you can change the user.
Find Your User and Group
In the Terminal use the id command to see your username and group
You will get a bunch of user groups, you need your primary user uid and group gid names
Change this back in /etc/apache2/httpd.conf
Restart Apache
Restart Apache and now you are running httpd as your local account.
Modify your hosts file
Modifying your hosts file enables you to override the domain name system(DNS) for a domain on a specific machine. DNS managementis useful when you want to test your site without the test link prior to going live with SSL,verify that an alias site works prior to DNS changes, and for other DNS-related reasons.For information about changing your DNS settings, see Changing DNS settings on Linux.
Modifying your hosts file causes your local machine to look directly atthe Internet Protocol (IP) address that you specify. Rackspace offersmanaged hosting solutions to assist withthe handling of these resources.
Modifying the hosts file involves adding two entries to it. Each entrycontains the IP address to which you want the site to resolve and a version ofthe Internet address. For example, add the following two entries points,www.domain.com and domain.com, to Rackspace’s current refreshed PHP5(PHP5-ITK) cluster:
This article provides instructions for locating and editing the hosts fileon the following operating systems:
- Microsoft® Windows® 10, Windows 8, Windows 7, andWindows Vista™
- Microsoft Windows NT™, Windows 2000, and Windows XP
- Linux®
- MacOS® X versions 10.0 through 10.1.5
- MacOS X versions 10.6 through 10.12
After you add the domain information and save the file, your system begins toresolve to the IP address that you specified. When testing is complete, removethese entries.
Windows
If you are using a Microsoft operating systemlike Windows 10, Windows 8, Windows 7, and Windows Vista you must run Microsoft Notepadas an administrator.
Windows 10 and Windows 8
Use the following instructions if you’re running Windows 10 or Windows 8:
- Press the Windows key.
- Type Notepad in the search field.
- In the search results, right-click Notepad and select Run asadministrator.
- From Notepad, open the following file:c:WindowsSystem32Driversetchosts
- Make the necessary changes to the file.
- Select File > Save to save your changes.
Windows 7 and Windows Vista
Use the following instructions if you’re running Windows 7 or Windows Vista:
- Select Start > All Programs > Accessories.
- Right-click Notepad and select Run as administrator.The Windows needs your permission UAC window appears.
- Click Continue to grant permission.Notepad opens.
- In Notepad, select File > Open.
- In the File name field, enter the following path:C:WindowsSystem32Driversetchosts
- Select Open.
- Make the necessary changes to the file.
- Select File > Save to save your changes.
Windows NT, Windows 2000, and Windows XP
Use the following instructions if you’re running Windows NT, Windows 2000, orWindows XP:
- Select Start > All Programs > Accessories > Notepad.
- Select File > Open.
- In the File name field, enterC:WindowsSystem32Driversetchosts.
- Select Open.
- Make the necessary changes to the file.
- Select File > Save to save your changes.
Linux
Use the following instructions if you’re running Linux:
- Open a Terminal window.
- Enter the following command to open the hosts file in a text editor:
- Enter your domain user password.
- Make the necessary changes to the file.
- Press Control-X.
- When you are asked if you want to save your changes, enter y.
MacOS X versions 10.0 through 10.12
This section provides instructions for modifying your hosts file if you arerunning MacOS X 10.0 through 10.12.
MacOS X 10.0 through 10.1.5
Use the following instructions if you’re running MacOS X 10.0 through 10.1.5:
- Open /Applications/Utilities/NetInfo Manager.
- To enable editing of the Network Information database (NetInfo), click thepadlock icon in the lower-left corner of the window.
- Enter your domain user password and select OK.
- In the second column of the browser view, select the node namedmachines.
- In the third column, select the entry named
localhost
. - From the Edit menu, select Duplicate.A confirmation alert appears.
- Click Duplicate.A new entry named
localhost copy
appears and its properties are displayed below the browser view. - Double-click the value of the
ip_address
property and enter the IPaddress of the other computer. - Double-click the value of the
name
property and enter the host name thatyou want use for the other computer. - Click the
serves
property and select Delete from the Edit menu. - From the File menu, select Save.A confirmation alert appears.
- Click Update this copy.
- Repeat steps 6 through 12 for each additional host entry that you want toadd.
- From the NetInfo Manager menu, select Quit.You do not need to restart the computer.
MacOS X 10.6 through 10.12
Use the following instructions if you’re running MacOS X 10.6 through 10.12:
- On your computer, select Applications > Utilities > Terminal to open aTerminal window.
- Enter the following command in the Terminal window to open the hostsfile:
- When you are prompted, enter your domain user password.
- Edit the hosts file.The file contains comments (lines that begin with the
#
symbol) and some default host name mappings (for example,127.0.0.1 – local host
). Add your new mappings after the default mappings. - To save the hosts file, press Control+X.
- When you are asked if you want to save your changes, enter y.
- To force your changes to take effect, flush the DNS cache by entering thefollowing command:
Experience what Rackspace has to offer.
Configuring My Hosts File For Https Macos Free
©2020 Rackspace US, Inc.
Hosts File Windows 10
Except where otherwise noted, content on this site is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License