如何在XAMPP上创build虚拟主机

我确信这个问题被多次提出,但是我没有遇到一个问题。 我正在使用XAMPP来configurationZend框架。

XAMPP在PORT 8081上运行,因为80正在被一些Windows进程占用,我需要使用虚拟主机,因为我在httpd-vhosts.config中configuration了以下代码,出现在C:/ xampp / apache / config / extra /

<VirtualHost *:80> ServerName comm-app.local DocumentRoot "C:/xampp/htdocs/CommunicationApp/public" SetEnv APPLICATION_ENV "development" <Directory "C:/xampp/htdocs/CommunicationApp/public" DirectoryIndex index.php AllowOverride All Order allow,deny Allow from all </Directory> </VirtualHost> 

并用127.0.0.1 comm-app.local更新hosts文件,并尝试重新启动apache,但显示错误。

 15:03:01 [Apache] Error: Apache shutdown unexpectedly. 15:03:01 [Apache] This may be due to a blocked port, missing dependencies, 15:03:01 [Apache] improper privileges, a crash, or a shutdown by another method. 15:03:01 [Apache] Press the Logs button to view error logs and check 15:03:01 [Apache] the Windows Event Viewer for more clues 15:03:01 [Apache] If you need more help, copy and post this 15:03:01 [Apache] entire log window on the forums 

我看到两个错误:

 <VirtualHost *:80> -> Fix to :8081, your POrt the server runs on ServerName comm-app.local DocumentRoot "C:/xampp/htdocs/CommunicationApp/public" SetEnv APPLICATION_ENV "development" <Directory "C:/xampp/htdocs/CommunicationApp/public" -> This is probably why it crashes, missing > DirectoryIndex index.php AllowOverride All Order allow,deny Allow from all </Directory> -> MIssing close container: </VirtualHost> 

修正版本:

 <VirtualHost *:8081> ServerName comm-app.local DocumentRoot "C:/xampp/htdocs/CommunicationApp/public" SetEnv APPLICATION_ENV "development" <Directory "C:/xampp/htdocs/CommunicationApp/public"> DirectoryIndex index.php AllowOverride All Order allow,deny Allow from all </Directory> </VirtualHost> 

有一点要提到:

您可以随时尝试运行命令:

 service apache2 configtest 

这会告诉你,当你有一个畸形的configuration,甚至可以告诉你问题在哪里。

此外,它有助于避免在LIVE系统中无法使用:

 service apache2 restart 

将closures,然后启动失败,这个configurationtesting你事先知道“哎呀我做错了什么,我应该首先解决这个问题”,但Apache本身仍然运行在旧的configuration。 🙂

步骤1) C:\ WINDOWS \ system32 \ drivers \ etc \打开“hosts”文件:

 127.0.0.1 localhost 127.0.0.1 test.com 127.0.0.1 example.com 

步骤2) xampp \ apache \ conf \ extra \ httpd-vhosts.conf

 <VirtualHost *:80> DocumentRoot C:/xampp/htdocs/test/ ServerName www.test.com </VirtualHost> <VirtualHost *:80> DocumentRoot C:/xampp/htdocs/example/ ServerName www.example.com </VirtualHost> 

步骤3) C:\ xampp \ apache \ conf \ httpd.conf。 向下滚动到最后的补充configuration部分,并find以下部分(在第500行左右),从第二行开头删除#,现在看起来像这样:

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

第4步)重新启动XAMPP,然后在浏览器中运行:

 www.example.com or www.test.com 

把这些代码写在C:\ xampp \ apache \ conf \ extra \ httpd-vhosts.conf文件的末尾,

 DocumentRoot "D:/xampp/htdocs/foldername" ServerName www.siteurl.com ServerAlias www.siteurl.com ErrorLog "logs/dummy-host.example.com-error.log" CustomLog "logs/dummy-host.example.com-access.log" common 

在虚拟主机标签之间。

并以pipe理员身份编辑文件System32 / Drivers / etc / hosts使用记事本

添加文件的底部

 127.0.0.1 www.siteurl.com 

只需将端口更改为8081 ,以下虚拟主机将工作:

 <VirtualHost *:8081> ServerName comm-app.local DocumentRoot "C:/xampp/htdocs/CommunicationApp/public" SetEnv APPLICATION_ENV "development" <Directory "C:/xampp/htdocs/CommunicationApp/public"> DirectoryIndex index.php AllowOverride All Order allow,deny Allow from all </Directory> </VirtualHost> 

将此代码添加到C:\ xampp \ apache \ conf \ extra \ httpd-vhosts.conf中

 <VirtualHost *:80> DocumentRoot "C:/xampp/htdocs" ServerName qa-staging.com ServerAlias www.qa-staging.com <Directory "c:/xampp/htdocs"> Order allow,deny Allow from all </Directory> </VirtualHost> 

现在在下面的文件中添加你的虚拟主机名。

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

127.0.0.1 qa-staging.com

如果您无法将此代码保存在主机文件中,请右键单击notpadselect以pipe理员身份运行,然后您可以保存自定义代码,然后重新启动您的XAMP

 <VirtualHost *:80> DocumentRoot "D:/projects/yourdirectry name" ServerName local.yourdomain.com <Directory "D:/projects/yourdirectry name"> Require all granted </Directory> </VirtualHost> 

保存Apacheconfiguration文件。

详细信息请参考这个

我使用下面的configuration来修复它。

  Listen 85 <VirtualHost *:85> DocumentRoot "C:/xampp/htdocs/LaraBlog/public" <Directory "C:/xampp/htdocs/CommunicationApp/public"> DirectoryIndex index.php AllowOverride All Order allow,deny Allow from all </Directory> </VirtualHost> 

在您的磁盘驱动器中:\ xampp \ apache \ conf \ extra \ httpd-vhosts.conf存在一个示例,您可以使用您的configuration对其进行编辑:

  ##<VirtualHost *:80> ##ServerAdmin webmaster@dummy-host.example.com ##DocumentRoot "C:/xampp/htdocs/dummy-host.example.com" ##ServerName dummy-host.example.com ##ServerAlias www.dummy-host.example.com ##ErrorLog "logs/dummy-host.example.com-error.log" ##CustomLog "logs/dummy-host.example.com-access.log" common ##</VirtualHost> 

那么如上所述,你必须在文件的底部添加: System32 / Drivers / etc / hosts

 127.0.0.1 www.dummy-host.example.com 

 127.0.0.1 dummy-host.example.com 

有可能运行您的代码与WWW或没有WWW,重新启动Apache并尝试在浏览器中:

 www.dummy-host.example.com 

要么

 dummy-host.example.com 

也许在第一次你必须像这样添加:

 http://dummy-host.example.com 

我已经将下面的configuration添加到httpd.conf中,并重新启动lampp服务,并开始工作。 感谢上述所有post,这些post帮助我逐一解决问题。

 Listen 8080 <VirtualHost *:8080> ServerAdmin webmaster@dummy-host2.example.com DocumentRoot "/opt/lampp/docs/dummy-host2.example.com" ServerName localhost:8080 ErrorLog "logs/dummy-host2.example.com-error_log" CustomLog "logs/dummy-host2.example.com-access_log" common <Directory "/opt/lampp/docs/dummy-host2.example.com"> Require all granted </Directory> </VirtualHost> 

简单,你可以看到下面的模板,并相应地使用它。 创build虚拟主机非常普遍,非常简单。 下面的模板肯定会起作用。

 <VirtualHost *:8081> DocumentRoot "C:/xampp/htdocs/testsite" ServerName testsite.loc ServerAlias www.testsite.loc <Directory "c:/xampp/htdocs/testsite"> Order allow,deny Allow from all </Directory> </VirtualHost> 

有关虚拟主机的更多参考,请访问此网站。 http://www.thegeekstuff.com/2011/07/apache-virtual-host

谢谢,