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.