I want to to retrieve a list of the virtual hosts which are currently loaded and listening for requests i.e not just grepping the config files.

It looks like apache2ctl -S does this but I am not 100% sure if that is just returning what is contained in the config files.

6 Answers 6


The command a2query -s works perfectly for me.

  • This was the answer for me +1
    – Neo
    May 26, 2018 at 21:02
  • Thanks that worked for me. works the same to list modules and configurations: a2query [-m [MODULES] -s [SITE] -c [CONF] ]
    – blessed
    Jan 12 at 6:48

I didn't found official documentation about it.

The command apache2ctl -S check site-enabled*.conf + httpd.conf files and show you if the syntax is correct and the list of virtual host (and some more informations).

But It doesn't check if virtualhosts are running, you can try to stop your Apache and launch again the command, the result will be the same.

So apache2ctl -S result is based on configuration files.


The apachectl -S documentation says this

-S Show the settings as parsed from the config file (currently only shows the virtualhost settings).

So you will only see those virtualhosts that are loaded in the config which is read when httpd starts.


You can use this command :

apache2ctl -t -D DUMP_VHOSTS

It will list all the enabled websites, the path to the conf file and the port that is used by the website


Another approach can be to list all the link under the directory /etc/apache2/sites-enables.

This hold a link to each site currently enabled, and dosnt require root permission.

A simple example taken from my home webserver:

ls -l /etc/apache2/sites-enabled/
lrwxrwxrwx 1 root root 39 dic 21 23:02 movement_report.conf -> ../sites-available/movement_report.conf
lrwxrwxrwx 1 root root 32 dic 15 23:34 teampass.conf -> ../sites-available/teampass.conf

The sites-available directory report other site apart from that:

ls -l /etc/apache2/sites-available/
totale 20
-rw-r--r-- 1 root root 1332 ago  8  2020 000-default.conf
-rw-r--r-- 1 root root 6338 ago  8  2020 default-ssl.conf
-rw-r--r-- 1 root root  331 dic 21 23:01 movement_report.conf
-rw-r--r-- 1 root root 1758 dic 15 23:34 teampass.conf
apache2ctl -S | grep -o -E 'alias (.*)|(namevhost|server) (.*)\s' | cut -d ' ' -f 2

Will output the list of configured domains and aliases

Works fine on Apache/2.4.38 (Debian)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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