a2query
Check if Apache module is enabled
TLDR
List enabled Apache modules
Check if a specific module is installed
List enabled virtual hosts
Display the currently enabled Multi Processing Module
Display Apache version
SYNOPSIS
a2query [-m|-s|-c|-v] [-M module|-S site|-C enabler] [-q] [-r] [-h]
PARAMETERS
-m
List all enabled Apache2 modules.
-s
List all enabled Apache2 sites (virtual hosts).
-c
List all enabled Apache2 configuration enablers (e.g., charset).
-v
Show the Apache2 version string.
-M module
Check if a specific Apache2 module is enabled. Returns 0 if enabled, 1 if not.
-S site
Check if a specific Apache2 site is enabled. Returns 0 if enabled, 1 if not.
-C enabler
Check if a specific Apache2 enabler is enabled. Returns 0 if enabled, 1 if not.
-q
Quiet mode. Suppresses informational output, only returning the exit status. Useful for scripting.
-r
Report Apache2 version. Similar to -v but often used internally for version checking scripts.
-h
Display a help message and exit.
DESCRIPTION
a2query is a utility command provided by the apache2 package on Debian-based systems (like Ubuntu) to inspect the status of Apache2 web server configurations.
It allows administrators to quickly determine which modules, virtual hosts (sites), and configuration enablers are currently active. This is particularly useful for debugging, configuration management, and verifying that intended configurations are loaded.
It works by checking the symbolic links in the mods-enabled, sites-enabled, and conf-enabled directories, which are managed by other Apache2 helper scripts like a2enmod, a2dismod, a2ensite, a2dissite, a2enconf, and a2disconf respectively.
CAVEATS
a2query primarily reports based on the symbolic links in *-enabled directories. It does not parse the Apache2 configuration files themselves to verify syntax or actual loading status by the Apache daemon. For full verification of syntax and operational status, apache2ctl configtest should be used.
The command is specific to Debian-based Apache2 installations that utilize the a2enmod/a2dismod management system. Other Linux distributions might manage Apache differently or provide alternative tools.
EXIT STATUS
The command returns an exit status of 0 on success (e.g., a specific module/site/enabler is found and enabled) and a non-zero status (typically 1) on failure or if the queried item is not enabled. This behavior makes it highly suitable for use in shell scripts for conditional logic.
LOCATION AND PERMISSIONS
On most Debian-based systems, a2query is typically located in /usr/sbin/a2query. While it primarily reads configuration, it often requires root privileges for execution due to the permissions on Apache's configuration directories (e.g., /etc/apache2/).
HISTORY
a2query is an integral part of the Apache2 package on Debian and Ubuntu systems. Its development emerged as part of the Debian packaging efforts for Apache2, specifically to complement the a2enmod, a2ensite, and a2enconf utilities. It provides a consistent and programmatic way to query the status of configured Apache components, allowing for more robust automation and management of the web server on these platforms.