What is the hosts file?
The hosts file is a system file. By binding the relationship between the domain name and the IP, when the machine accesses the domain name, it will find the corresponding file from this file. If the record is found, the corresponding web page will be opened immediately. If not found, DNS public network resolution will be used to open the web page. Therefore, it is a good way to speed up access and local development and bind domain names.
Mac computer sets hosts local virtual domain name access steps:
Step 1:Find the terminal in the mac computer and open it (click on the upper left corner of the desktop [Magnifying glass
] to "Search", enter "Term
" or "term
" and the "Terminal" will be displayed, and then open it.) As shown below :
Step 2:Inputsudo vim /ect/hosts
in the opened window and press "Enter key" Enter
Step 3:Enter the password set by your MAC computer and press Enter
The following content will be displayed
Step 4:In the input method English mode, enteri
to enter the editing mode. This An INSERT will be displayed in the lower left corner. Press the down and right keys on the keyboard to move the cursor to the end of the last line, and then press Enter to start a new line. Enter127.0.0.1 www.test.com as shown below
This domain name can be replaced with your own domain name
Step 5:Then Press theESC key
, then enter:wq
and press Enter. It will be automatically saved and you can end the editor.
In this way, the hosts domain name has been added successfully. You can check whether it takes effect byping www.test.com
.
At this point, the Mac computer has set up the hosts file and set up access to the local virtual domain name. This will make it much more convenient for us to develop and demonstrate the local website program. Hurry up and try it!
Note:phpstudy V8 PHP development integrated environment can be added to the local hosts file by default when adding a domain name, but currently only supports the Windows version. We look forward to the early development of the MAC version of phpstudy Finish!
The above is the detailed content of How to set up hosts on Mac computer (steps with pictures and text). For more information, please follow other related articles on the PHP Chinese website!