How to List All Virtual Hosts in Apache Web Server

Apache virtual host configuration allows you to run multiple websites on the same server, that means you can run more than one website on the same Apache web server. You simply create a new virtual host configuration for each of your websites and restart the Apache configuration to start serving the website.

On Debian/Ubuntu, the recent version of Apache configuration files for all virtual hosts are stored in the /etc/apache2/sites-available/ directory. So, it makes really difficult to go through all of these virtual host configuration files to fix any configuration errors.

To make things easier, in this article we will show you how to list all enabled apache virtual hosts on a web server using a single command on the terminal. This method will also help you to see a few other useful apache configurations.

This is practically helpful in a scenario where you are assisting a company to fix their web server issues remotely, yet you do not know their current apache web server configurations, in regards to virtual hosts.

Read Also: How to Check Which Apache Modules are Enabled/Loaded in Linux

It will help ease searching for the virtual host of a specific website in the apache config files and assist in troubleshooting any apache issues, where you’ll, in most cases start with checking of the currently enabled virtual hosts before looking into the logs.

To list all enabled virtual hosts on the web server, run the following command in a terminal.

# apache2ctl -S   [On Debian/Ubuntu]
# apachectl -S    [On CentOS/RHEL]
# httpd -S

You will get a list of all configured virtual hosts as well as another important apache/httpd server configurations.

List Apache Virtual Host Configurations
VirtualHost configuration:
*:80                   is a NameVirtualHost
         default server (/etc/httpd/conf.d/
         port 80 namevhost (/etc/httpd/conf.d/
         port 80 namevhost (/etc/httpd/conf.d/
         port 80 namevhost (/etc/httpd/conf.d/
         port 80 namevhost tecmint.lan (/etc/httpd/conf.d/tecmint.lan.conf:1)
                 alias www.tecmint.lan
ServerRoot: "/etc/httpd"
Main DocumentRoot: "/var/www/html"
Main ErrorLog: "/etc/httpd/logs/error_log"
Mutex default: dir="/run/httpd/" mechanism=default 
Mutex mpm-accept: using_defaults
Mutex authdigest-opaque: using_defaults
Mutex proxy-balancer-shm: using_defaults
Mutex rewrite-map: using_defaults
Mutex authdigest-client: using_defaults
Mutex ssl-stapling: using_defaults
Mutex proxy: using_defaults
Mutex authn-socache: using_defaults
Mutex ssl-cache: using_defaults
PidFile: "/run/httpd/"
User: name="apache" id=48 not_used
Group: name="apache" id=48 not_used

From the above output, we can clearly see which ports and IP addresses are configured for each website. We will also see each website virtual host configuration file and their location.

This comes very helpful, when you are troubleshooting or fixing any apache virtual host configuration errors or you simply want to see a list of all enabled virtual host summary on a web server.

That’s all! You might also find these following related articles on Apache web server.

  1. 3 Ways to Check Apache Server Status and Uptime in Linux
  2. 13 Apache Web Server Security and Hardening Tips
  3. How to Change Default Apache ‘DocumentRoot’ Directory in Linux
  4. How to Hide Apache Version Number and Other Sensitive Info

If you have any questions relating to Apache HTTP server, use the comment form below to reach us.

Aaron Kili
Aaron Kili is a Linux and F.O.S.S enthusiast, an upcoming Linux SysAdmin, web developer, and currently a content creator for TecMint who loves working with computers and strongly believes in sharing knowledge.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

Got Something to Say? Join the Discussion...

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.