Apache is a modular system where its modules extend the functionality of the main program. A module could be installed into the system, and Apache would then be configured to load and use the module during its startup.

Some of the most used Apache modules, for example, are PHP and SSL. They enable the hosting of PHP applications and provide encrypted web traffic.

Apache modules could be enabled using the LoadModule directive in the configuration files.

Steps to enable or disable Apache modules:

  1. Install required Apache module if it's not already installed.
  2. Check if required module is already loaded or enabled (optional).
    $ apachectl -t -D DUMP_MODULES
    Loaded Modules:
     core_module (static)
     so_module (static)
     watchdog_module (static)
     http_module (static)
     log_config_module (static)
     logio_module (static)
     version_module (static)
     unixd_module (static)
     access_compat_module (shared)
     alias_module (shared)
     auth_basic_module (shared)
     authn_core_module (shared)
     authn_file_module (shared)
     authz_core_module (shared)
     authz_host_module (shared)
     authz_user_module (shared)
     autoindex_module (shared)
     deflate_module (shared)
     dir_module (shared)
     env_module (shared)
     filter_module (shared)
     mime_module (shared)
     mpm_event_module (shared)
     negotiation_module (shared)
     reqtimeout_module (shared)
     setenvif_module (shared)
     socache_shmcb_module (shared)
     status_module (shared)

    You can also use the -M option instead which is just a shortcut to the above command.

    $ apachectl -M
  3. Add required modules into Apache configuration file using the LoadModule directive.
    LoadModule ssl_module /usr/lib/apache2/modules/mod_ssl.so
    • Ubuntu and other Debian derivatives along with openSUSE and SLES has a2enmod utility installed and could be used to easily load Apache modules without having to manually configure the LoadModule directive.
      $ sudo a2enmod ssl
      [sudo] password for user:
      Considering dependency setenvif for ssl:
      Module setenvif already enabled
      Considering dependency mime for ssl:
      Module mime already enabled
      Considering dependency socache_shmcb for ssl:
      Module socache_shmcb already enabled
      Enabling module ssl.
      See /usr/share/doc/apache2/README.Debian.gz on how to configure SSL and create self-signed certificates.
      To activate the new configuration, you need to run:
        systemctl restart apache2
    • CentOS, Fedora and Red Hat distributions will automatically load the module so no further action is required.
    Options Debian, Ubuntu openSUSE and SLES Fedora Core, CentOS, RHEL macOS homebrew xampp
    a2enmod support yes yes no no no no
    Loadmodule directive n/a LoadModule <module_name>_module <module_location>/mod_<module_name>.so
  4. Restart Apache service for the modules to be loaded.
  5. Check if module is now enabled.
    $ apachectl -M
    Loaded Modules:
     core_module (static)
     so_module (static)
     watchdog_module (static)
     http_module (static)
     log_config_module (static)
     logio_module (static)
     version_module (static)
     unixd_module (static)
     access_compat_module (shared)
     alias_module (shared)
     auth_basic_module (shared)
     authn_core_module (shared)
     authn_file_module (shared)
     authz_core_module (shared)
     authz_host_module (shared)
     authz_user_module (shared)
     autoindex_module (shared)
     deflate_module (shared)
     dir_module (shared)
     env_module (shared)
     filter_module (shared)
     mime_module (shared)
     mpm_event_module (shared)
     negotiation_module (shared)
     reqtimeout_module (shared)
     setenvif_module (shared)
     socache_shmcb_module (shared)
     ssl_module (shared)
     status_module (shared)
  6. Remove the added LoadModule directive or comment out the line by adding # at the beginning to disable loading the module.
    #LoadModule ssl_module /usr/lib/apache2/modules/mod_ssl.so

    Users of Ubuntu and other Debian derivatives along with openSUSE and SLES can use a2dismod utility to disable Apache modules.

    $ sudo a2dismod ssl
    [sudo] password for user:
    Module ssl disabled.
    To activate the new configuration, you need to run:
      systemctl restart apache2
  7. Restart Apache service for the modules to be unloaded.
Discuss the article:

Comment anonymously. Login not required.