xampp虚拟主机配置(xampp搭建本地服务器)
本文目录一览:
- 1、如何配置XAMPP的虚拟主机
- 2、Mac os XAMPP配置了虚拟主机之后IP地址访问403
- 3、Xampp-Apache配置虚拟主机问题
- 4、xampp5.6.31怎么配虚拟主机
- 5、如何配置 Apache 的虚拟主机
- 6、如何使用xampp搭建运行php的虚拟主机
如何配置XAMPP的虚拟主机
你需要一些顶级域名访问方式来访问你本地的项目文件而不是目录方式访问,这时候就需要配置虚拟主机,给你的目录绑定一个域名(本地的话可以通过修改 hosts 文件随便绑定什么域名比如 或者 localdemo)。
现在假定你有两个目录,一个存在于 /xampp/htdocs/5hoom,另一个存在于 /xampp/htdocs/chinadoto 。
现在你想要在本地测试的时候访问 对应的目录是 /xampp/htdocs/5hoom ,访问 对应的目录是 /xampp/htdocs/chinadoto 。
懂得 Apache配置的其实就可以绕开了,因为 XAMPP 无非就是集成了 APache 之类的环境集成包,实现多域名也就是通过配置 Apache 实现的。
当然网上搜索到的方法很多,但是网上的信息都是转载来转载去的,有的方法我怀疑是否验证过是否正确都不知道。以下的方法是我亲测的,如果你按照我的配置还是 无法实现本地多域名调试的话,可能是因为你的 XAMPP 的版本和我的不一致造成的。你可以在下面评论告知我,我会给你一一解答。以下配置针对的是 XAMPP Windows 1.7.1 版本。
1、首先修改C盘WINDOWS\system32\drivers\etc目录下的 hosts 文件,用记事本打开,加入:
127.0.0.1
127.0.0.1
2、打开xampp\apache\conf\httpd.conf文件,搜索 “.. conf/extra/httpd-vhosts.conf”,确保前面没有 # 注释符,也就是确保引入了 vhosts 虚拟主机配置文件。
开启了httpd-vhosts.conf,默认的httpd.conf默认配置失效(确保 httpd-vhosts.conf 文件里也开启了虚拟主机配置,见第3条),访问此IP的域名将全部指向 vhosts.conf 中的第一个虚拟主机。
3、在虚拟主机设置文件xampp\apache\conf\extra\httpd-vhosts.conf里设置:
取消 NameVirtualHost *:80 前面的 ##,这样就启用了 vhosts.conf ,默认的httpd.conf默认配置失效。虚拟主机配置将只设置在 httpd-vhosts.conf 里。
VirtualHost *:80
DocumentRoot /xampp/htdocs/5hoom
ServerName
/VirtualHost
VirtualHost *:80
DocumentRoot /xampp/htdocs/chinadoto
ServerName
/VirtualHost
4、 设置完了第3条之后,你会发现访问 localhost直接指向到设置的 a 那个路径去了,这个问题在第2条有讲。也就是开启了 vhosts 后,默认的 httpd 的配置就会失效了,默认的访问就指向到 vhosts 里的第一条设置去了。这时候你要把 localhost 的目录配置给设置回来。
VirtualHost *:80
DocumentRoot /xampp/htdocs/
ServerName localhost
/VirtualHost
至此,XAMPP 的虚拟主机设置完毕,现在 访问 localhost 还是原来的 XAMPP 的帮助指南,访问 将指向到绑定的 5hoom 目录,访问 将指向到绑定的 chinadoto 目录。
Mac os XAMPP配置了虚拟主机之后IP地址访问403
httpd.conf
第一步:注销,如下样式:
#DocumentRoot "C:/myenv/apache/htdocs"
第二步:启动虚拟主机的配置,如下样式:
Include conf/extra/httpd-vhosts.conf
第三步:配置httpd-vhosts.conf,增加如下样式:
VirtualHost *:80
DocumentRoot "D:/myblog2"
ServerName seophp.example.com
DirectoryIndex test.html index.html index.htm index.php
Directory /
Options FollowSymLinks
#AllowOverride None 不许可别人修改我们的页面
AllowOverride None
Order allow,deny
Allow from all
/Directory
/VirtualHost
注意标点符号,apache对中英标点号是不检测的,但是运行会出问题。
如果不行就看一下\apache\logs\error.log转上看看。
你这些是否是多余的
《httpd.conf检查了httpd-vhosts.conf是打开的
httpd-vhosts.conf中的配置如下:
NameVirtualHost 127.0.0.1:80
VirtualHost 127.0.0.1:80
DocumentRoot "D:/xampp/htdocs"
ServerName localhost
/VirtualHost
》
Xampp-Apache配置虚拟主机问题
是不是之前有删除过apache。apache没删除干净吧。
你运行网站报什么错了,是什么界面。
或者:在httpd.conf配置文件查找 Lsiten 80,改成别的端口,可以改特殊一点,肯定不会用到的,比如3369等。果没有php相关配置行正确的好,那端口方面应该没有错误。
建议现运行apachectl -t ,看看配置文件的检查结果。
xampp5.6.31怎么配虚拟主机
具体安装步骤:
1、双击 mysql-installer-community-5.6.24.0 安装,接受用户许可协议。
2、选择安装类型:
1)Developer Default 默认安装类型,开发模式,该选项代表典型个人用桌面工作站,假定机器上运行着多个桌面应用程序,将MySQL服务器配置成使用最少的系统资源;
2)Server only 仅作为服务器,该选项代表服务器,MySQL服务器可以同其它应用程序一起运行,例如FTP、email和web服务器,MySQL服务器配置成使用适当比例的系统资源;
3)Client only 仅作为客户端,Full 完全安装类型,Custom自定义安装类型 ;
4)作为服务器类型数据库安装,需选自定义安装类型,安装需自定义安装路径。
3、选择安装选项,MySql Servers必选项,核心组件,可根据系统位数对应选择,Applications应用和MySQL Connectors连接器可不选,Documentation类似于帮助文档资料可选。
4、选择文件安装目录路径及数据保存目录路径。
5、选择配置选项, Developer Machine(开发机器),Server Machine(服务器),Dedicated MySQL Server Machine(专用MySQL服务器),前二个上面有讲描述,专用MySQL服务器-该选项代表只运行MySQL服务的服务器,假定没有运行其它应用程序,MySQL服务器配置成使用所有可用系统资源。如果服务程序及库装在同一台机上,建议选Server Machine,下面可勾选Show Advanced Options高级选项,作为初学者,选择Developer Machine即可。
6、设置root密码,配置windows服务默认。
7、配置日志,可自定义路径存放日志文档方便管理,Error Log错误日志:记录启动、运行或停止mysqld时出现的问题; General Log通用日志:记录建立的客户端连接和执行的语句,占用资源多默认不启用; Show Query Log慢查询日志:记录所有执行时间超过long_query_time秒的所有查询或不使用索引的查询,Bin Log二进制日志,记录所有更改数据的语句,还用于复制,启用主从备份时一定要启用此日志。
8、应用服务配置安装,直到结束。
注:
1、自定义安装才能选择路径。
2、根据作用选择安装服务类型。
如何配置 Apache 的虚拟主机
1、基于ip地址的虚拟主机
复制代码代码如下:
Listen 80
VirtualHost 172.20.30.40
DocumentRoot /home/httpd/html1
ServerName
ErrorLog /usr/local/apache/logs/error1_log
CustomLog /usr/local/apache/logs/access1_log combined
/VirtualHost
VirtualHost 172.20.30.50
DocumentRoot /home/httpd/html2
ServerName
ErrorLog /usr/local/apache/logs/error2_log
CustomLog /usr/local/apache/logs/access2_log combined
/VirtualHost
2、基于IP 和多端口的虚拟主机配置
复制代码代码如下:
Listen 172.20.30.40:80
Listen 172.20.30.40:8080
Listen 172.20.30.50:80
Listen 172.20.30.50:8080
VirtualHost 172.20.30.40:80
DocumentRoot /www/example1-80
ServerName
/VirtualHost
VirtualHost 172.20.30.40:8080
DocumentRoot /www/example1-8080
ServerName
/VirtualHost
VirtualHost 172.20.30.50:80
DocumentRoot /www/example2-80
ServerName
/VirtualHost
VirtualHost 172.20.30.50:8080
DocumentRoot /www/example2-8080
ServerName
/VirtualHost
3、单个IP 地址的服务器上基于域名的虚拟主机配置
复制代码代码如下:
# Ensure that Apache listens on port 80
Listen 80
# Listen for virtual host requests on all IP addresses
NameVirtualHost *:80
VirtualHost *:80
DocumentRoot /www/example1
ServerName
ServerAlias example1.com. *.example1.com
# Other directives here
/VirtualHost
VirtualHost *:80
DocumentRoot /www/example2
ServerName
# Other directives here
/VirtualHost
如果您感觉上面的文章还不够详细可以看下下面的文章:
实验目标:在apache实现基于域名的虚拟主机
实验用的XAMPP版本为1.7.7,内含apache版本为2.2.21
实验前准备:
1. 为了测试不同的域名,在Windows/System32/drivers/etc/下觅得hosts文件,在其中添加实验用的域名若干,如 -
复制代码代码如下:
127.0.0.1 test1.net
127.0.0.1 test2.net
如此,则在浏览器中输入该俩域名时,Windows将其解析为127.0.0.1本地地址。即,在浏览器中访问localhost, test1.net, test2.net均可访问XAMPP的欢迎页。
2. 在apache目录下建立目录,以放置您不同的网站。为保护XAMPP原有的htdocs中的欢迎页内容,实验另外建立了与htdocs平级的htdocs1目录,在其下建立了test1.net, test2.net两个子目录用以放置实验用的网站。如下 -
apache/htdocs1/test1.net - 放置test1.net网站内容
apache/htdocs1/test2.net - 放置test2.net网站内容
在这两个目录中各新建hello world一网页 index.html,内容 -
复制代码代码如下:
HTML
HEAD/HEAD
BODY
H1hello~, 这是[对应的网站名,用以区别].net/H1/BODY
/HTML
实验步骤:
1. 找到apache/conf/httpd.conf, 将其中的
ServerAdmin
ServerName
DocumentRoot
注释掉。
2. 在httpd.conf中,找到行
Include "conf/extra/httpd-vhosts.conf"
如被注释则解注。该文件记载了虚拟主机的参数。[以前虚拟主机参数是直接填写在httpd.conf中的,为了更好地组织文件,将其分离出去,类似于某些编程语言一样。因此httpd.conf中include它,即相当于把它的内容填在了httpd.conf中。]
3. 这个httpd-vhosts.conf文件格式基本如下 -
复制代码代码如下:
#blah-blah
NameVirtualHost *:80
#blah-blah
#blah-blah
VirtualHost *:80
ServerAdmin XXXXXXXX
DocumentRoot "XXXXXXXX"
ServerName XXXXXXX
ServerAlias XXXXXX
ErrorLog "logs/XXXXXX-error.log"
CustomLog "logs/XXXXXXX-error.log" combined
/VirtualHost
需要修改的,就是VirtualHost中的参数了。这个可以参见apache官方文档。根据实验域名,可以增加两个VirtualHost:
复制代码代码如下:
VirtualHost *:80
ServerAdmin adm@test1.net
DocumentRoot "C:/xampp/htdocs1/test1.net"
ServerName test1.net
ServerAlias
ErrorLog "logs/test1-error.log"
CustomLog "logs/test1-access.log" combined
Directory "C:/xampp/htdocs1/test1.net"
order allow,deny
allow from all
/Directory
/VirtualHost
VirtualHost *:80
ServerAdmin adm@test2.net
DocumentRoot "C:/xampp/htdocs1/test2.net"
ServerName test2.net
ServerAlias
ErrorLog "logs/test1-error.log"
CustomLog "logs/test1-access.log" combined
Directory "C:/xampp/htdocs1/test2.net"
order allow,deny
allow from all
/Directory
/VirtualHost
注意,如果不在各VirtualHost中定义Directory的可访问性,你将遇到的是Access Forbidden!就连原来的localhost也是。
4. 由于之前注释掉了httpd.conf中的ServerName, DocumentRoot等,为了仍然能以localhost访问原XAMPP欢迎页,就在增加一个VirtualHost,如下 -
复制代码代码如下:
VirtualHost *:80
ServerAdmin adm@localhost
DocumentRoot "C:/xampp/htdocs"
ServerName localhost
ErrorLog "logs/localhost-error.log"
CustomLog "logs/localhost-access.log" combined
Directory "C:/xampp/htdocs"
order allow,deny
allow from all
/Directory
/VirtualHost
为了避免出错,把它放置在第一个Virtualhost位置。
至此,apache基于域名的虚拟主机配置完成。可以通过访问XAMPP欢迎页,通过和访问各自的主页。
#
# Virtual Hosts
#
# 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
# URL:;
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.
#
# Use name-based virtual hosting.
#
NameVirtualHost *:80
#
# 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 VirtualHost block.
#
VirtualHost *:80
ServerAdmin kongdaoxian@gmail.com
DocumentRoot "E:/skydao/apache2/htdocs"
ServerName localhost
ServerAlias
ErrorLog "logs/localhost-error.log"
CustomLog "logs/localhost-access.log" combined
Directory "E:/skydao/apache2/htdocs"
order allow,deny
allow from all
/Directory
/VirtualHost
VirtualHost *:80
ServerAdmin kongdaoxian@gmail.com
DocumentRoot "E:/skydao/apache2/htdocs/project1"
ServerName project1.com
ServerAlias
ErrorLog "logs/project1-error.log"
CustomLog "logs/project1-access.log" combined
Directory "E:/skydao/apache2/htdocs/project1"
order allow,deny
allow from all
/Directory
/VirtualHost
VirtualHost *:80
ServerAdmin kongdaoxian@gmail.com
DocumentRoot "E:/skydao/apache2/htdocs/zendTest/public"
ServerName zendTest.com
ServerAlias
DirectoryIndex index.php
Directory /
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
/Directory
/VirtualHost
VirtualHost *:80
ServerAdmin kongdaoxian@gmail.com
DocumentRoot "E:/skydao/apache2/htdocs/testRewrite"
ServerName testRewrite.com
ServerAlias
# DirectoryIndex index.php
Directory /
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
/Directory
/VirtualHost
VirtualHost *:80
ServerAdmin kongdaoxian@gmail.com
DocumentRoot "E:/skydao/apache2/htdocs/test"
ServerName test.com
ServerAlias
ErrorLog "logs/zendTest-error.log"
CustomLog "logs/zendTest-access.log" combined
Directory "E:/skydao/apache2/htdocs/test"
order allow,deny
allow from all
/Directory
/VirtualHost
如何使用xampp搭建运行php的虚拟主机
安装XAMPP启动apache 和mysql后, 服务器就运行了。在浏览器中输入localhost就可以看到xampp的欢迎界面。下载一个简单的php文件或者用任何编辑器保存以下代码htmlbody?phpecho "Hello World";?/body/html保存在XAMPP的htdocs文件夹下,比如test.php然后在浏览器中输入localhost/test.php就可以看到hello world了。注意文件夹名字htdocs不用输入。
xampp虚拟主机配置的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于xampp搭建本地服务器、xampp虚拟主机配置的信息别忘了在易优之家进行查找喔。
发表评论
暂时没有评论,来抢沙发吧~