在 Xampp 中创建虚拟主机 Windows 10

Create a Virtual Host in Xamp Windows 10

昨晚我将 windows 7 更新为 windows 10。

结果是尝试 运行 我在 windows 10 中的本地 Apache 服务器,即 windows 上 运行ning 7.I 已尝试卸载和安装另一个版本的 xampp 然后我想到我必须更改 apache 的默认端口才能使其成为 运行.

我改了httpd.conf

Listen 80Listen 1234

ServerName localhost:80ServerName localhost:1234

并在 xampp 控制面板配置 -> 服务和端口设置中 。我也更改主端口

现在我可以使用 localhost:1234/phpmyadmin 访问 phpmyadmin。 现在我的问题是创建虚拟主机

所以我在主机 (C:\Windows\System32\drivers\etc\hosts) 文件中添加了

127.0.0.1       sample.local
127.0.0.1       anothersample.local

还有我的虚拟主机 (D:\xampp\apache\conf\extra\httpd-vhosts.conf) 文件

<VirtualHost *:1234>
    DocumentRoot "D:/xampp/htdocs/sample"
    ServerName sample.local
</VirtualHost>

<VirtualHost *:1234>
    DocumentRoot "D:/xampp/htdocs/anothersample"
    ServerName anothersample.local
</VirtualHost>

我确定包含了上面的虚拟主机文件

我已经重新启动了我的 Apache,但我的虚拟主机似乎无法正常工作。有人能指出我错过了什么吗?

谢谢@ShamSUP 和@maytham-ɯɐɥıλɐɯ 我可以通过卸载 xampp.

来解决我的问题

然后按照说明进行操作

我将在这里列出我完成的步骤。

  1. Windows+R 并键入 appwiz.cpl 并使用打开或关闭 Windows 功能并通过展开安装 IIS 管理器控制台 Internet Information Services->Web Management Tools->然后检查 IIS Management Console
  2. Windows+R 并输入 InetMgr.exe 并回车,然后展开 Site 右键单击​​它然后单击 Edit Bindings
  3. http 端口从 80 更改为 8080

然后我安装 XAMPP 并配置虚拟主机

主机(C:\Windows\System32\drivers\etc\hosts) 文件

127.0.0.1       sample.local
127.0.0.1       anothersample.local

vhost (D:\xampp\apache\conf\extra\httpd-vhosts.conf) 文件

<VirtualHost *:80>
    DocumentRoot "D:\xampp\htdocs\sample"
    ServerName sample.local
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "D:/xampp/htdocs/anothersample"
    ServerName anothersample.local
</VirtualHost>

默认情况下在windows 虚拟主机中未注释

重新启动 apache 和 mysql.The 虚拟主机后 运行 now.I 希望这对以后的人有所帮助。

也许我的问题不一样。 以上答案对我不起作用 Windows 10,XAMPP 便携式 5.6.30

我的 XAMPP 在端口 80 上工作,但是当我设置虚拟主机时,它的本地主机也会转到虚拟主机文件夹。所以http://localhost also shows the content of http://mydrupal

我也只是将其添加到 /apache/conf/extra/httpd-vhosts.conf 文件中。

<VirtualHost *:80>
    DocumentRoot "D:/xampp/htdocs"
    ServerName localhost
    <Directory D:/xampp/htdocs>
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

Windows7 不需要以上代码。

对于虚拟主机 - mydrupal

<VirtualHost *:80>
DocumentRoot "D:/vhosts/drupal"
ServerName mydrupal
<Directory D:/vhosts>
    AllowOverride All
    Require all granted
</Directory>
</VirtualHost>

希望这对您有所帮助。

E:\xampp\apache\conf\extra\httpd-vhosts.conf

<VirtualHost *:80>
    DocumentRoot "E:/xampp/htdocs/dev2017/schools"
    ServerName dev.schools
    <Directory "E:/xampp/htdocs/dev2017/schools">

    </Directory>
</VirtualHost>

C:\Windows\System32\drivers\etc\hosts

127.0.0.1       dev.schools

NOTE: Restar Xampp Server.

Type URL: http://dev.schools