使用Xampp配置本地域名访问的步骤

本文详细介绍了如何在Windows环境下使用Xampp配置本地域名,以便于PHP开发中多个项目通过不同域名进行访问。主要步骤包括:安装Xampp,启用httpd.conf中的vhost功能,编辑hosts文件添加自定义域名,以及配置httpd-vhosts.conf设置项目目录。
摘要由CSDN通过智能技术生成

需求背景

使用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转换功能,如下图红色部分,去掉前面的#号

blob.png

3、配置host文件,添加一个自定义的域名(自己随便添加),如 yuanfei.dev.com

blob.png


4、配置http-vhost.conf文件,第一个红色标注部分是启用80端口,第二个红色部分就是配置项目的目录

,域名为host文件中配置的域名:yuanfei.dev.com

blob.png


附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 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值