使用 XAMPP 托管多个本地站点
我刚开始使用 XAMPP,所以这对某些人来说可能很简单。
我有一些 php 项目,我希望能够在本地调试并在浏览器中查看(不是同时进行,但每次我想处理不同的项目时不必更改配置文件/复制项目文件夹)。
在 IIS 上,您可以设置多个站点以从您的计算机提供服务,我正在 XAMPP 中寻找类似的东西。使用 IIS 时,我向 Windows 主机文件添加了多个记录,这样我就可以通过键入友好的 Web 样式地址(例如 http ://myproject1.dev)
谢谢。
I'm new to using XAMPP so this may be simple to some people.
I have a few php projects that I would like to be able to debug locally and view in the browser (not concurrently, but without having to change config files/copy project folders each time I want to work on a different project).
On IIS, you could set up multiple sites to serve from your machine, and I'm looking for something similar in XAMPP. When using IIS, I added multiple records to the Windows hosts file so I could access the locally hosted sites by typing friendly web-style addresses (like http://myproject1.dev)
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
格雷格,你已经快到了——你需要(就像摩西说的那样)设置虚拟主机。
因此,如果您的 Windows 主机文件有
您的虚拟主机文件 (httpd-vhosts.conf) 可能如下所示:
进行任何更改后,不要忘记重新启动 Web 服务器。
Greg, you're almost there--you need (like Moses said) to setup virtual hosts.
So if your Windows hosts file has
Your virtual hosts file (httpd-vhosts.conf) might look like:
Don't forget to restart the web server after you make any changes.
这个问题差不多十年前就被问过,上面的答案有点过时了。请注意,安装 XAMPP 时,可以在仪表板外获取虚拟主机的“操作方法”。
从“欢迎使用 XAMPP for Windows”页面(本地主机/仪表板,首次加载本地主机时的默认设置),单击顶部菜单栏中的“HOW-TO”指南。从那里,查找链接“配置虚拟主机”,该链接将引导您进入本地主机页面“http: //localhost/dashboard/docs/configure-vhosts.html”
简而言之,该过程涉及编辑“httpd-vhosts.conf”文件(通常位于 C:\XAMPP\apache\conf\extra 中)并将该文件的内容替换为以下内容:
可以通过克隆条目并修改 DocumentRoot 和 ServerName 指令以及端口号(例如 TLS (SSL) 的 443)来获得其他虚拟主机(包括 SSL 主机)。您可以在网上找到用于创建和签名的教程你自己的证书,如果你想走那条路。
最后一步是让您的 Windows 计算机将浏览器指向虚拟域的 Apache 主机(例如上面的 http://mysite.local)。本地)。使用文本编辑器(笔记本电脑即可)以管理员身份将以下条目附加到您的主机文件中,该文件位于此处:
将此条目附加到主机文件中:
重要 - 您必须重新启动 Windows 计算机或新计算机主机不会回应。有些文档会告诉您只需重新启动浏览器和 Apache 服务器,但我发现这还不够。
IME、主机系统和 Apache 指令可能比较特殊,因此请耐心等待。您可能需要重建配置、重新启动 Apache,并多次重新启动计算机。
This question was asked almost ten years ago, and the answers above are a bit dated. Note that XAMPP has a "How-To" for virtual hosts avilable off the dashboard, when you install it.
From the "Welcome to XAMPP for Windows" page (localhost/dashboard, the default when you first load localhost) click on the "HOW-TO" Guides in the top menu bar. From there, look for the link "Configure Virtual Hosts" which will lead you to the localhost page "http://localhost/dashboard/docs/configure-vhosts.html"
In a nutshell, the process involves editing the "httpd-vhosts.conf" file (typically in C:\XAMPP\apache\conf\extra) and replacing the contents of that file with something like this:
Additional vhosts (including SSL hosts) can be had by cloning the entry, and modifying DocumentRoot and ServerName directives and port numbers (e.g. 443 for TLS (SSL)). You can find tutorials on the web for creating and signing your own certificate, if you want to go that route.
The final step is to get your Windows machine to point your browser to the Apache host for your virtual domain (e.g. above, http://mysite.local). Using a text editor (Notebook will do) as administrator append the following entry onto your hosts file, which lives here:
Append this entry to the hosts file:
IMPORTANT - you must restart your Windows machine or the new host will not respond. Some documentations will tell you just to restart the browser and Apache server, but I've found that's not sufficient.
IME, the hosts system and Apache directives can be particular, so be patient. You may need to rebuild configs, restart Apache, and restart your machine more than once.
我想补充一下最新信息。
XAMMP 默认使用端口 80,我们可以发布 1 个网站。我还使用 IIS 进行 .Net 项目。对此,我将除80端口之外的端口设置为XAMMP。所以我避免冲突。
当我们要发布多个网站时,我们应该对httpd.conf(这是当前的名称)进行以下操作。
1.设置端口
在httpd.conf 文件中找到#Listen 表达式。
将 Listen 80 更改为 Listen 8000(或您想要的其他任何内容)
如果您需要 3 个不同的网站,请键入其他网站,包括每行 1 个定义,如下所示。
2.定义通过端口访问的站点的文件路径
再次在 httpd.conf 文件中查找。
按如下方式识别每个网站的文件夹。
正如您所看到的,我在 XAMMP 目录中的 htdocs 目录下创建了 3 个名为 8000、8001、8002 和 8003 的目录。
在 XAMMP 上重新启动 Apahche 服务器。
您现在可以查看第三个站点,例如 http://localhost:8003 或 http://192.168.1.1:8003/。
希望有用。
I would like to make an additional in terms of up to date information.
XAMMP uses port 80 by default and we are able to publish 1 website. I also use IIS for .Net projects. In this respect, I set the port to XAMMP except the 80 port. So I avoid a conflict.
When we want to publish more than one website, we should do the following operations to httpd.conf (this is the current name).
1. Setting the ports
Find the #Listen expression in the httpd.conf file.
Change Listen 80 to Listen 8000 (or whatever else you want)
If you need 3 different websites, type the others, including 1 definition on each line, as follows.
2. Define the file paths of sites accessed through ports
Again, find in the httpd.conf file.
Identify the folders of each website as follows.
As you would see, I've created 3 directories called 8000, 8001, 8002 and 8003 under the htdocs directory within the XAMMP directory.
Restart your Apahche server on XAMMP.
You can now view your 3rd site, such as http://localhost:8003 or http://192.168.1.1:8003/.
Hope to be useful.