When using PHP to develop a website, every time you test your website, you usually use localhost/dirname/filename.php to access the program you wrote.
But sometimes we need to simulate real scenes, such as access through the domain name, if you have rented the server, then you can directly upload the code to the server, through the domain name access, but this may be more troublesome, because the upload is not complex, but the time is relatively more.
So you can create a local virtual host, bind a domain name to the virtual host, and then the domain name to the IP address to 127.0.0.1, Note that the domain name of the original IP may be 112.252.36.1 (assuming that the domain name corresponds to the real IP), Then when we visit this domain name, we will automatically access the ip127.0.0.1, not the real IP.
We can use this domain name to access our local program, that is, replace localhost/index.php with www.test.com/index.php, note that this is not the Internet host. Instead of pointing to the remote 112.252.36.1 (assuming that the domain corresponds to the real IP), we just let the local DNS server point to the IP that corresponds to the domain name we set 127.0.0.1.
The above-written explanations of what, if there is doubt, you can check some Apcache,dns server information, in fact, do not understand the principles, but also no problem.
The specific steps are as follows:
Click the other Options menu----"Select site domain name management. Such as
Initially, the site is empty. Then you can fill in the domain name of the site, the root directory for your project root directory, if necessary, you can also set a second domain name, the site port can set its own, usually 80. Once you've set up, click Add, and the added domain will appear on the left. Then click Save Settings and generate the default file.
As an example, I added the following:
Website Domain name: www.beyond.com
Root directory: D:\phpStudy\WWW\test (note that the site domain name is not necessarily the same as the project name, but at the best)
Second domain name: www.test.com
Website Port: 80
After you save the settings, the phpstudy automatically restarts.
At this point, you have to modify the Hosts file, also click the other Options menu----"Open the hosts
You'll see something like this and I cut some of the pictures
At this point, you only need to add a line at the end, the content is the domain name set by the 127.0.0.1,, note that the previous # number represents the comment, so do not add #
If I add the following according to my settings, the result
And then save it, and it worked.
First look at this is the file in the test directory index.php and content
Then through the browser, access www.beyond.com
Visit www.test.com
See here, I believe you've already created a new site.
Create a local virtual host using Phpstudy