php开发网站时,默认情况下我们是使用localhost
访问我们的设计的网站,那么怎么在本机上配置一个域名,方便我们访问呢。
其实很简单,这里假设要配置的域名为test.com
,分三个步骤:
(注意:这里是Apache服务器的配置方法)
文件位置: C:\Windows\System32\drivers\etc\hosts
文件内容:
# Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
# 102.54.94.97 rhino.acme.com # source server
# 38.25.63.10 x.acme.com # x client host
# localhost name resolution is handled within DNS itself.
127.0.0.1 localhost
我们只需要添加一行:
127.0.0.1 test.com
文件位置:..\phpStudy\PHPTutorial\Apache\conf\httpd.conf
搜索:
#LoadModule vhost_alias_module modules/mod_vhost_alias.so
去掉前面的注释符号#
即可
找到:..\phpStudy\PHPTutorial\Apache\conf
增加配置如下:
<VirtualHost _default_:80>
DocumentRoot "E:\htdocs\test.com"
ServerName test.com
<Directory "E:\htdocs\test.com">
Options -Indexes +FollowSymLinks +ExecCGI
AllowOverride All
Order allow,deny
Allow from all
Require all granted
</Directory>
</VirtualHost>
其中的E:\htdocs\test.com
为网站位置,请自行修改。
暂无评论,赶紧发表一下你的看法吧。