List all virtual hosts served by Apache2 on Ubuntu

By using virtual host configurations, it is possible for more than one website to be served by the same Apache web server on the same machine. Virtual hosting makes it easy to run multiple websites from the same server. You simply make a new virtual host configuration for each new website that you want to set up and then reload the Apache configuration.

On recent versions of Apache on Ubuntu/Debian, the configuration files for all virtual hosts (enabled or not) are stored in /etc/apache2/sites-available/. It is very tedious and time consuming to go through all these configurations to make sense of them. Apache provides us with a tool that we can run from the command line which gives us a summary of our virtual hosts.

To list all enabled virtual hosts, run the following command in a terminal:

apache2ctl -S

We will then see a list of the enabled virtual hosts and a summary of their configurations like this:

1.2.3.4:80  is a NameVirtualHost
default server abc.com (/etc/apache2/sites-enabled/000-default:1)
port 80 namevhost abc.com (/etc/apache2/sites-enabled/000-default:1)
port 80 namevhost def.com (/etc/apache2/sites-enabled/def.com:1)
Syntax OK

We can use it to see which ports and which IP addresses are configured for each website being served. We will also see where the configuration file for each virtual host is located and what it is called. This tool also tells us if the syntax in our virtual host configurations is okay.

This comes in handy when troubleshooting errors in virtual host configurations or when looking for a summary of all the sites hosted by the server.

We hope you found this PHP tutorial helpful.

Thank Tutorial Arena for This Tutorial.
Show your appreciation with a +1...