Useful httpd or apachectl Options

The Apache HTTP Server Control Interface Program – apachectl – is a shell script that acts as a front end to the Apache Web Server that can be used to perform administrative tasks for the httpd daemon. It can be used as a pass-through to the httpd binary relaying any options passed to it with/without modifications. So effectively whatever options you pass to apachectl can also be passed to the httpd (or apache2 in some operation systems) program/binary on the command line with or without minor changes.

So let’s see what are the different useful and interesting things we can do with various cli options.

Note: Most popular Unix-like or Unix-based platforms like Mac OS, FreeBSD and Linux distributions like Ubuntu, Debian, CentOS, Fedora, etc. ship apachectl with their standard Apache installations. But if apachectl is not available or ain’t working as expected for you, don’t worry as I’ll also specify the httpd equivalents.

Find Config Location

The -V option can help us locate the main server config file alongside giving other information like the server version, architecture, current mpm in use, magic number, configuration directives httpd was compiled with, etc.

# apachectl -V # or httpd -V
Server version: Apache/2.4.29 (Ubuntu)
Server built:   2020-03-13T12:26:16
Server's Module Magic Number: 20120211:68
Server loaded:  APR 1.6.3, APR-UTIL 1.6.1
Compiled using: APR 1.6.3, APR-UTIL 1.6.1
Architecture:   64-bit
Server MPM:     prefork
  threaded:     no
    forked:     yes (variable process count)
Server compiled with....
 -D APR_HAS_SENDFILE
 -D APR_HAS_MMAP
 -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
 -D APR_USE_SYSVSEM_SERIALIZE
 -D APR_USE_PTHREAD_SERIALIZE
 -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
 -D APR_HAS_OTHER_CHILD
 -D AP_HAVE_RELIABLE_PIPED_LOGS
 -D DYNAMIC_MODULE_LIMIT=256
 -D HTTPD_ROOT="/etc/apache2"
 -D SUEXEC_BIN="/usr/lib/apache2/suexec"
 -D DEFAULT_PIDLOG="/var/run/apache2.pid"
 -D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
 -D DEFAULT_ERRORLOG="logs/error_log"
 -D AP_TYPES_CONFIG_FILE="mime.types"
 -D SERVER_CONFIG_FILE="apache2.conf"

Syntax Check Config

The configtest or -t options can help us run syntax parsing tests on all the configuration files to ensure there’s no error and a start or restart of the server won’t fail.

# apachectl configtest
Syntax OK
# apachectl -t # or httpd -t
Syntax OK

List All Config Files

The primary config file that is picked up by httpd is httpd.conf or apache2.conf located at, well, read the Find Config Location section above. Now in a lot of cases the configuration will be split across multiple files for obvious reasons – better organisation. If one wants to find out all the config files included in the main config file, then the -D DUMP_MODULES is just meant to do that.

# apachectl -D DUMP_INCLUDES # or httpd -D DUMP_INCLUDES
Included configuration files:
  (*) /usr/local/etc/apache24/httpd.conf
    (536) /usr/local/etc/apache24/Includes/no-accf.conf

Find Server Root

The -D DUMP_RUN_CFG and -V options can help locate the server root where the server is supposed to “live”, i.e., contain configurations at least, logs, etc.

# apachectl -D DUMP_RUN_CFG # or httpd -D DUMP_RUN_CFG
ServerRoot: "/etc/apache2"
Main DocumentRoot: "/var/www/html"
Main ErrorLog: "/var/log/apache2/error.log"
Mutex default: dir="/var/run/apache2/" mechanism=default
Mutex mpm-accept: using_defaults
Mutex watchdog-callback: using_defaults
Mutex rewrite-map: using_defaults
PidFile: "/var/run/apache2/apache2.pid"
Define: DUMP_RUN_CFG
User: name="www-data" id=33
Group: name="www-data" id=33

# apachectl -V # or httpd -V
...
 -D HTTPD_ROOT="/etc/apache2"
...

You need to eye for ServerRoot in the first output and HTTPD_ROOT in the next one. The latter is compiled into httpd where as the former overrides it once the main configuration file is read during the server startup.

DUMP_RUN_CFG gives a lot of other details like the system user/group httpd will be running as, location of the pid file, various mutex and their mechanisms in use, main server’s DocumentRoot, etc.

List All Static and Shared Modules

A lot of the Apache Web Server feature set is usually powered by plug-and-play modules (or shared objects). Static modules that httpd was compiled with can be listed via the -l option where as all the dynamic/shared modules currently loaded/enabled (along with the static ones again) can be fetched via the -D DUMP_MODULES option.

# apachectl -l # or httpd -l
Compiled in modules:
  core.c
  mod_so.c
  http_core.c

# apachectl -D DUMP_MODULES # or httpd -D DUMP_MODULES
Loaded Modules:
 core_module (static)
 so_module (static)
 http_module (static)
 mpm_prefork_module (shared)
 authn_file_module (shared)
 authn_core_module (shared)
 authz_host_module (shared)
 authz_groupfile_module (shared)
 authz_user_module (shared)
 authz_core_module (shared)
 access_compat_module (shared)
 auth_basic_module (shared)
 reqtimeout_module (shared)
 filter_module (shared)
 mime_module (shared)
 log_config_module (shared)
 env_module (shared)
 headers_module (shared)
 setenvif_module (shared)
 version_module (shared)
 unixd_module (shared)
 status_module (shared)
 autoindex_module (shared)
 dir_module (shared)
 alias_module (shared)

Dump Parsed Virtual Hosts

So you made a few changes to your virtual hosts configuration and want to debug/check it ? -D DUMP_VHOSTS can help here.

# apachectl -D DUMP_VHOSTS # or httpd -D DUMP_VHOSTS
VirtualHost configuration:
*:80                   is a NameVirtualHost
         default server catchall (/etc/apache2/sites-enabled/000-catchall.conf:1)
         port 80 namevhost catchall (/etc/apache2/sites-enabled/000-catchall.conf:1)
         port 80 namevhost codingshower.com (/etc/apache2/sites-enabled/codingshower.conf:1)

The same can be achieved with apachectl -S or httpd -S which is a synonym for -D DUMP_VHOSTS -D DUMP_RUN_CFG.

Send Signals

We can pass-through signals for start, stop, and restart for instance.

# apachectl start # httpd -k start
# apachectl restart # httpd -k restart
# apachectl stop # httpd -k stop

Help!

Of course there’s the -h option for help that lists literally everything that you can do with the apachectl program. As you might have already guessed, a lot of apachectl -h will be similar to what you’d see for httpd -h.

Leave a Reply

Your email address will not be published. Required fields are marked *