需求背景
使用php开发了一年的时间,对于很多项目来说都是限定使用80端口来访问,若是要相应的搭建本地的环境,就必须使用本地域名映射的方式访问不同的项目。
环境
php的集成开发环境xampp,下载相应的xampp安装包(百度软件中心下载),本文以windows系统为例
xamp安装目录:D:\xampp
hots文件目录:C:\Windows\System32\drivers\etc
apache httpd.conf目录:D:\xampp\apache\conf
apache httpd-vhosts.conf文件目录:D:\xampp\apache\conf\extra
配置步骤
1、安装好xampp
2、修改httpd.conf文件,启用vhost转换功能,如下图红色部分,去掉前面的#号
3、配置host文件,添加一个自定义的域名(自己随便添加),如 yuanfei.dev.com
4、配置http-vhost.conf文件,第一个红色标注部分是启用80端口,第二个红色部分就是配置项目的目录
,域名为host文件中配置的域名:yuanfei.dev.com
附http.conf和host文件以及http-vhost.conf文件的配置
http.conf
#
# This is the main Apache HTTP server configuration file. It contains the
# configuration directives that give the server its instructions.
# See <URL:http://httpd.apache.org/docs/2.4/> for detailed information.
# In particular, see
# <URL:http://httpd.apache.org/docs/2.4/mod/directives.html>
# for a discussion of each configuration directive.
#
# Do NOT simply read the instructions in here without understanding
# what they do. They're here only as hints or reminders. If you are unsure
# consult the online docs. You have been warned.
#
# Configuration and logfile names: If the filenames you specify for many
# of the server's control files begin with "/" (or "drive:/" for Win32), the
# server will use that explicit path. If the filenames do *not* begin
# with "/", the value of ServerRoot is prepended -- so "logs/access_log"
# with ServerRoot set to "/usr/local/apache2" will be interpreted by the
# server as "/usr/local/apache2/logs/access_log", whereas "/logs/access_log"
# will be interpreted as '/logs/access_log'.
#
# NOTE: Where filenames are specified, you must use forward slashes
# instead of backslashes (e.g., "c:/apache" instead of "c:\apache").
# If a drive letter is omitted, the drive on which httpd.exe is located
# will be used by default. It is recommended that you always supply
# an explicit drive letter in absolute paths to avoid confusion.
#
# ServerRoot: The top of the directory tree under which the server's
# configuration, error, and log files are kept.
#
# Do not add a slash at the end of the directory path. If you point
# ServerRoot at a non-local disk, be sure to specify a local disk on the
# Mutex directive, if file-based mutexes are used. If you wish to share the
# same ServerRoot for multiple httpd daemons, you will need to change at
# least PidFile.
#
ServerRoot "D:/xampp/apache"
#
# Mutex: Allows you to set the mutex mechanism and mutex file directory
# for individual mutexes, or change the global defaults
#
# Uncomment and change the directory if mutexes are file-based and