Installing an Apache module adds server capabilities that are not part of the active base package, such as web application firewalling, external authentication, or FastCGI support. Using the packaged-module workflow keeps the shared object, default configuration files, and service integration aligned with the distribution's Apache layout.
Apache can load functionality either from modules compiled into the server binary or from shared objects declared with LoadModule. On Debian and Ubuntu, packaged shared modules usually install their .load and optional .conf files under /etc/apache2/mods-available, then become active through links in /etc/apache2/mods-enabled.
Examples below use Debian or Ubuntu with apt, apache2, apache2ctl, and a2query. Not every feature needs a separate package: some modules, such as rewrite or headers, already ship with the base Apache package and only need enabling, while third-party or distribution-specific modules can use different package names and activation rules.
$ apt-cache search '^libapache2-mod-' | grep security2 libapache2-mod-security2 - Tighten web applications security for Apache
Packaged module names on Debian and Ubuntu usually start with libapache2-mod-. If the feature already ships with apache2 and no separate package exists, enable the module instead of trying to install it as a new package.
$ sudo apt install libapache2-mod-security2 Reading package lists... Building dependency tree... Reading state information... The following NEW packages will be installed: libapache2-mod-security2 liblua5.1-0 libyajl2 modsecurity-crs ##### snipped ##### Setting up libapache2-mod-security2 ... apache2_invoke: Enable module security2
The example uses mod_security2 because it is a current Debian-family package that installs both the shared module and its default configuration. Substitute the package that matches the feature being added.
$ sudo a2query -m security2 security2 (enabled by maintainer script)
Debian-family module packages often enable the module automatically during installation. If the query reports that the module is disabled, run sudo a2enmod security2 before continuing.
$ sudo apache2ctl configtest Syntax OK
The AH00558 hostname warning can appear before Syntax OK when a global ServerName is unset. That warning does not block the module from loading.
A failed syntax test means the new module or its configuration introduced an error. Correct the reported file and line before restarting Apache.
Related: How to test Apache configuration
$ sudo systemctl restart apache2
Package installation can attempt a restart automatically, but a manual restart after a clean config test makes the final activation point explicit.
$ sudo apache2ctl -M | grep security2 security2_module (shared)
Use the short module name with a2query and the loaded symbol name ending in _module when filtering apache2ctl -M output.