Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

How can I create a dynamic webpage in PHP (protected via htaccess) that displays a list of all domains and sub domains currently setup via vhosts?

share|improve this question

2 Answers 2

up vote 1 down vote accepted

There is no straight way to achieve this. You would have to parse the output of localhost/server-info or the Apache Vhost-confs in php, perhaps extract all ServerName and ServerAlias lines.

You could simplify this, if you normalize your vhost-confs - i.e. every vhost has one file /sites-enabled/sub.domain.com.conf and every ServerAlias line has only one Alias and does not use wildcards. Otherwise it could be a pretty large project...

share|improve this answer

The canonical way to get this info from apache is to use httpd -S (which on some OSes such as debian/ubuntu and probably others would be apache2 -S. Depending on the environment, there might be a bunch of environment variables set before this command will word. On debian/ubuntu, you'd run . /etc/apache2/envvars ; /usr/sbin/apache2 -S

As a side note, since you mention .htaccess, don't use .htaccess when you have permissions to alter the actual apache configuration. .htaccess is meant for unprivileged users that can't alter the apache config and presents performance and security problems when it is enabled.

share|improve this answer
    
Or "apachectl -S" would work too. Then you might not even have to set the env vars. (But I am not sure about it.) –  Raffael Luthiger Jan 19 '12 at 16:21
    
Don't know why I reserve the vote down for this question but I was able to find: code.google.com/p/vhost-indexer which did the job. –  John Magnolia Jan 19 '12 at 18:11

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.