2013-03-26 83 views
2

我期望能够构建一个脚本,它将显示在我的Apache(Ubuntu)开发机器下运行的所有虚拟主机。从php脚本显示虚拟主机?

到今天为止,我还没有发现接近我想要的任何实例或任何东西,这简直是:

“显示本机上运行的所有虚拟主机”。 (ServerName,别名等)。

我在想我可能会读取/ etc/apache2/sites-available文件夹,其中包含虚拟主机的所有conf文件,但在走下这条路之前,我想我会先问到这里。

+1

我觉得读conf文件是唯一的出路。 – chrislondon 2013-03-26 20:34:35

+1

虚拟主机文件可以是任何地方或主要conf文件的一部分。如果apache没有获取定义的虚拟主机的api,我看不到任何简单的方法来解决这个问题。除非你保证一定的安装配置文件。 – 2013-03-26 20:35:39

回答

2

可以使用apachectl(或apache2ctl)命令信号的httpd Apache服务器转储虚拟主机信息:

apache2ctl -St 

通过以下链接可使用apachectl发送信号和httpd flags

下面是它看起来像我的Apache/Ubuntu系统上(我是一个Web开发人员与一群虚拟主机):

VirtualHost configuration: 
wildcard NameVirtualHosts and _default_ servers: 
*:80     is a NameVirtualHost 
     default server 127.0.1.1 (/etc/apache2/sites-enabled/000-default:1) 
     port 80 namevhost 127.0.1.1 (/etc/apache2/sites-enabled/000-default:1) 
     port 80 namevhost adaleco (/etc/apache2/sites-enabled/adaleco:1) 
     port 80 namevhost amcham (/etc/apache2/sites-enabled/amcham:1) 
     port 80 namevhost cake (/etc/apache2/sites-enabled/cake:1) 
     port 80 namevhost cakeplate (/etc/apache2/sites-enabled/cakeplate:1) 
     port 80 namevhost coord (/etc/apache2/sites-enabled/coord:1) 
     port 80 namevhost dru1 (/etc/apache2/sites-enabled/dru1:1) 
     port 80 namevhost flaming (/etc/apache2/sites-enabled/flaming:1) 
     port 80 namevhost flaming6 (/etc/apache2/sites-enabled/flaming6:1) 
     port 80 namevhost food (/etc/apache2/sites-enabled/food:1) 
     port 80 namevhost fun (/etc/apache2/sites-enabled/fun:1) 
     port 80 namevhost marc (/etc/apache2/sites-enabled/marc:1) 
     port 80 namevhost sugar (/etc/apache2/sites-enabled/sugar:1) 
     port 80 namevhost vol (/etc/apache2/sites-enabled/vol:1) 
     port 80 namevhost xmas (/etc/apache2/sites-enabled/xmas:1) 
Syntax OK 
+0

嘿,斯科特,为你做这个工作还是你有其他想法(不知道是否通过脚本你想要一个本地的PHP API)? – 2013-03-27 03:10:13

+0

我想要的是一个php脚本,当我在本地机器上激活时,只会吐出上面显示的画面,所以我写了一个快速的PHP脚本来读取启用站点的目录,并且只是吐出每个文件的内容。不过,我想我会重新使用apache2ctl命令。 谢谢,约翰。完成后,我会发布我的脚本。 – 2013-03-29 14:51:46