keepcalculator

06 Numbers and Powers

List Enabled Virtual Hosts in Apache Web Server

Card No. 06·86815 · Updated · Standard formula, shown below

To list enabled virtual hosts in Apache, you run apachectl -S (or httpd -S) on most Linux distributions, which prints a summary of all configured virtual hosts along with their ports and document roots. This command reads the main configuration file and all included files, so it shows exactly what Apache will serve when it starts.

What Virtual Hosts Are

Virtual hosts let one Apache instance serve multiple websites from a single server. Each host is defined by a <VirtualHost> block in the configuration, typically specifying a domain name, port, and document root. Apache distinguishes between two types:

  • Name-based virtual hosts – the server uses the Host header sent by the browser to pick the right site. This is the most common setup for shared hosting and lets many domains share one IP address.
  • IP-based virtual hosts – each site gets its own IP address or port. This is used when SSL certificates or legacy applications require a dedicated IP.

On Debian/Ubuntu systems, virtual host files live in /etc/apache2/sites-available/ and are enabled by symlinking them into /etc/apache2/sites-enabled/. On RHEL/CentOS, the files are usually in /etc/httpd/conf.d/ and are read directly.

Why You Need to List Them

Knowing which virtual hosts are actually enabled helps you troubleshoot several common situations:

  • You added a new site but it doesn’t appear – the file might not be enabled.
  • You removed a site but it still loads – the old config might still be active.
  • You’re seeing the wrong site for a domain – another virtual host may be catching the request first.
  • You need to audit what’s running before a server migration or security review.

Running apachectl -S gives you a definitive answer in seconds, without having to manually trace includes or guess which files are symlinked.

Using apachectl -S

The -S flag (show settings) is the standard way to display the virtual host configuration. Here’s what the output looks like on a typical Debian system:

VirtualHost configuration:
*:80                   is a NameVirtualHost
     default server example.com (/etc/apache2/sites-enabled/000-default.conf:1)
     port 80 namevhost example.com (/etc/apache2/sites-enabled/000-default.conf:1)
     port 80 namevhost blog.example.com (/etc/apache2/sites-enabled/blog.conf:1)
     port 80 namevhost shop.example.com (/etc/apache2/sites-enabled/shop.conf:1)

This tells you the port, the domain name, and the exact file and line where each host is defined. If a virtual host is defined but not enabled, it won’t appear here – which is exactly what you want to know.

On some systems, the command is httpd -S instead of apachectl -S. Both work; apachectl is a wrapper that calls httpd with the right flags. On Windows, you’d use httpd.exe -S from the Apache bin directory.

Other Ways to List Virtual Hosts

While apachectl -S is the most reliable method, there are alternatives depending on what you need:

  • List enabled files on Debian/Ubuntu: ls -l /etc/apache2/sites-enabled/ shows which symlinks are active. This tells you the filenames but not the domains inside them.
  • Grep the config: grep -r "ServerName" /etc/apache2/sites-enabled/ lists every domain name that Apache will respond to. Add ServerAlias to see alternate names.
  • Use a2query (Debian/Ubuntu): a2query -s lists enabled sites in a compact format, but it doesn’t show ports or document roots.
  • Check the running process: ps aux | grep apache shows the master process but not the virtual host details.

For most purposes, apachectl -S is the best single command because it parses the entire configuration, including any Include directives, and reports errors if something is malformed.

Common Problems and Fixes

Here are typical issues people run into when listing virtual hosts:

  • Command not found: If apachectl isn’t in your PATH, try /usr/sbin/apachectl -S or /usr/local/apache/bin/apachectl -S. On macOS with Homebrew, it’s often /usr/local/opt/httpd/bin/apachectl -S.
  • Permission denied: The command may need root privileges to read config files. Use sudo apachectl -S.
  • Syntax errors: If a config file has a typo, Apache will refuse to start and -S will print an error instead of the list. Run apachectl configtest to check syntax first.
  • No output: If there are no virtual hosts defined, the output will just show the main server. This happens on a fresh install before any sites are added.
  • Duplicate warnings: If two virtual hosts use the same domain and port, Apache will use the first one and warn about the duplicate. The -S output will show both, which helps you spot the conflict.

How to Enable or Disable a Virtual Host

Listing is only half the job – you often need to change what’s enabled. On Debian/Ubuntu, the commands are:

  1. Create a config file in /etc/apache2/sites-available/, e.g., mysite.conf.
  2. Enable it with sudo a2ensite mysite (this creates the symlink).
  3. Reload Apache with sudo systemctl reload apache2 (or sudo service apache2 reload).
  4. Disable it with sudo a2dissite mysite and reload again.

On RHEL/CentOS, there’s no a2ensite; you just place the .conf file in /etc/httpd/conf.d/ and restart with sudo systemctl reload httpd. Removing the file disables the site.

After any change, run apachectl -S again to confirm the new state. This is a good habit before and after every configuration change.

Frequently Asked Questions

What is the difference between sites-available and sites-enabled?

sites-available holds all virtual host config files, whether they’re in use or not. sites-enabled contains symlinks to the files you want active. Apache only reads the enabled directory, so a file in available but not enabled is ignored. This separation lets you keep configs for future use without them interfering.

How do I list virtual hosts with their SSL certificates?

apachectl -S doesn’t show certificate details. To see SSL configuration per virtual host, you can grep the enabled files for SSLCertificateFile or use openssl s_client -connect yourdomain:443 to inspect the certificate served on that port. For a full audit, consider tools like ssl-cert-check or a configuration parser.

Why does my new virtual host not show up in apachectl -S?

Most likely the file isn’t enabled. Check that the symlink exists in sites-enabled (Debian/Ubuntu) or that the file is in conf.d (RHEL). Also verify the file has a valid <VirtualHost> block and a ServerName. Run apachectl configtest to catch syntax errors that might prevent it from being loaded.

Can I list virtual hosts without root access?

If the config files are world-readable (they usually are), you can run apachectl -S as a normal user. However, if Apache’s PID file or logs aren’t readable, you might get partial output. In practice, most users run it with sudo to avoid permission issues.

What does “default server” mean in the output?

The default server is the first virtual host defined for a given IP:port combination. When a request arrives with a Host header that doesn’t match any ServerName or ServerAlias, Apache serves this default host. In the -S output, it’s marked with “default server” and is usually the first entry.

How do I see virtual hosts on Windows?

Open a command prompt as Administrator, navigate to your Apache bin directory (e.g., C:\Apache24\bin), and run httpd.exe -S. The output format is the same as on Linux. If the command isn’t recognized, add the bin directory to your PATH or use the full path.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More cards in this drawer

The whole Numbers and Powers drawer →