win10搭建apache虚拟主机

1.修改hosts文件

进入C:\Windows\System32\drivers\etc,我的电脑并没有发现hosts文件。管理员进入cmd运行命令:

for /f %P in ('dir %windir%\WinSxS\hosts /b /s') do copy %P %windir%\System32\drivers\etc & echo %P & Notepad %P

生成了一个hosts文件,然后完成修改并保存到C:\Windows\System32\drivers\etc目录,这一步最好用记事本修改,开始我用的其它编辑器,估计是编码问题没有解决。

# 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
#	::1             localhost
192.168.56.1 windows10.microdone.cn
127.0.0.1	www.0630.com 0630.com
127.0.0.1	www.doubletree.com doubletree.com

2.修改httpd.conf文件

这里最好把端口改成80,我的80端口被pid=4占用,搜了一下是被SQL SERVER占用了,关掉改80端口。

# Change this to Listen on specific IP addresses as shown below to 
# prevent Apache from glomming onto all bound IP addresses.
#
#Listen 12.34.56.78:80
Listen 80

把以下注释去掉(如果被注释)。

# Virtual hosts
Include conf/extra/httpd-vhosts.conf

网上有的说需要把以下注释去掉,但是我没有去掉,但亲测能正常工作,如果有大神请留言一下讲一下这个:

#LoadModule vhost_alias_module modules/mod_vhost_alias.so

3.修改httpd-vhosts.conf文件

我比较虎,把前两个默认的删掉了,已经找不回来了,直接加了两个自己的,前一个是lavarel框架的入口,另一个是没有框架的php网站。这一步应注意DocumentRoot和Directory的文件范围应该在httpd.conf的ServerRoot文件夹中,否则在windows下是forbiden错误。

# Virtual Hosts
#
# Required modules: mod_log_config

# If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at 
# 
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.

#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any  block.
#

	ServerAdmin [email protected]
	DocumentRoot "D:\phpenvir\Apache24\htdocs\blog\public"
	ServerName www.0630.com
	ServerAlias 0630.com
	
		allow from all
		AllowOverride all
		Options +indexes
	
	ErrorLog "logs/0630.com-error.log"
    CustomLog "logs/0630.com-access.log" common



	ServerAdmin [email protected]
	DocumentRoot "D:\phpenvir\Apache24\htdocs\DoubleTree"
	ServerName www.doubletree.com
	ServerAlias doubletree.com
	
		allow from all
		AllowOverride all
		Options +indexes
	
	ErrorLog "logs/doubletree.com-error.log"
    CustomLog "logs/doubletree.com-access.log" common


4.重启httpd服务

你可能感兴趣的:(apache,php)