apachectl on Linux: get the entire Apache vhost configuration in one output

Want to help support this blog? Try out Oh Dear, the best all-in-one monitoring tool for your entire website, co-founded by me (the guy that wrote this blogpost). Start with a 10-day trial, no strings attached.

We offer uptime monitoring, SSL checks, broken links checking, performance & cronjob monitoring, branded status pages & so much more. Try us out today!

Profile image of Mattias Geniar

Mattias Geniar, January 02, 2016

Follow me on Twitter as @mattiasgeniar

If you’re tasked with debugging a problem on a new Linux server, one you don’t manage or know, it can be a little bit tricky to know where to find the config files, where all data is stored, etc. I find this especially the case on webservers, where everyone can have its own ideas on where to store configurations or log files.

But instead of using grep recursively over the /etc/* directories to find configurations, you can also use the apachectl tool (or if you’re on Ubuntu/Debian, the apache2ctl tool).

Dump all vhosts and their config files

This little-known gem reads the Apache configuration and dumps out all the vhost information, together with the file location that holds its entire config.

$ apachectl -D DUMP_VHOSTS
VirtualHost configuration:
10.5.200.1:80       is a NameVirtualHost
         default server localhost (/etc/httpd/conf/extra/httpd-vhosts.conf:31)
         port 80 namevhost localhost (/etc/httpd/conf/extra/httpd-vhosts.conf:31)
         port 80 namevhost www.domain1.be (/usr/local/directadmin/data/users/admin/httpd.conf:23)
                 alias www.domain2.be
                 alias domain2.be
         port 80 namevhost www.othersite.be (/usr/local/directadmin/data/users/othersite/httpd.conf:23)
                 alias www.othersite.be
                 alias othersite.be
...

This is a lot easier than first grepping for keywords in /etc, then finding the include statements that refer back to /usr/local, which may include things from even another place.

Show all loaded Apache modules

Another quick command, this one shows all the Apache modules that have been loaded.

$ apachectl -D DUMP_MODULES
Loaded Modules:
 core_module (static)
 authn_file_module (static)
 authn_dbm_module (static)
 ...

Show main configuration directives (without vhosts)

And this one shows you the ‘main’ Apache configuration, basically all configured parameters without specific vhost information.

$ apachectl -D DUMP_RUN_CFG
ServerRoot: "/etc/httpd"
Main DocumentRoot: "/var/www/html"
Main ErrorLog: "/var/log/httpd/error_log"
PidFile: "/var/run/httpd.pid"
...

Summary: show everything at once

If you want a quick command to show you all of the above, use this.

$ apachectl -S; apachectl -M

This beats searching configuration files and following includes and references.



Want to subscribe to the cron.weekly newsletter?

I write a weekly-ish newsletter on Linux, open source & webdevelopment called cron.weekly.

It features the latest news, guides & tutorials and new open source projects. You can sign up via email below.

No spam. Just some good, practical Linux & open source content.