Home » Enable/Disable Apache Modules in Centos7

Enable/Disable Apache Modules in Centos7

How to Enable and Disable Apache Modules in Centos 7

Apache is a very powerful and flexible web server. Its modular structure allows it to perform in various environments and on several platform types. There are several modules that help extend its functionality like the deflate, ssl and rewrite modules. You can enable the modules you need and disable the ones you don’t need easily through SSH/terminal. By default, there are many modules enabled on your Apache server and several of them are unnecessary. So, as a part of Apache performance tuning or for another reason, you may need to enable or disable particular modules.

On Debian or Ubuntu, you have the a2enmod and a2dismod commands to do this. However, on Centos7, you do it in a different way. You will need to enable or disable the modules from configuration files by commenting out the ones you do not need and loading only the ones you need. In Debian, you can do the same by using the a2enmod or a2dismod script and specifying the required module. For example: a2enmod deflate or a2dismod http2.

To find out which modules are installed and available on your server, you can use the following command on centos 7.

httpd -M

It will produce a list of the modules available for use on your server. The list will look something like the following:

$ httpd -M

Loaded Modules:

 core_module (static)

 so_module (static)

 http_module (static)

 access_compat_module (shared)

 actions_module (shared)

 alias_module (shared)

 allowmethods_module (shared)

 auth_basic_module (shared)

 auth_digest_module (shared)

 authn_anon_module (shared)

 authn_core_module (shared)

 authn_dbd_module (shared)

 authn_dbm_module (shared)

 authn_file_module (shared)

 authn_socache_module (shared)

 authz_core_module (shared)

 authz_dbd_module (shared)

 authz_dbm_module (shared)

 authz_groupfile_module (shared)

 authz_host_module (shared)

 authz_owner_module (shared)

 authz_user_module (shared)

 autoindex_module (shared)

 cache_module (shared)

 cache_disk_module (shared)

 cache_socache_module (shared)

 data_module (shared)

 dbd_module (shared)

 deflate_module (shared)

 dir_module (shared)

 dumpio_module (shared)

 echo_module (shared)

 env_module (shared)

 expires_module (shared)

 ext_filter_module (shared)

 filter_module (shared)

 headers_module (shared)

 include_module (shared)

 info_module (shared)

 log_config_module (shared)

 logio_module (shared)

 macro_module (shared)

 mime_magic_module (shared)

 mime_module (shared)

 negotiation_module (shared)

 remoteip_module (shared)

 reqtimeout_module (shared)

 request_module (shared)

 rewrite_module (shared)

 setenvif_module (shared)

 slotmem_plain_module (shared)

 slotmem_shm_module (shared)

 socache_dbm_module (shared)

 socache_memcache_module (shared)

 socache_shmcb_module (shared)

 status_module (shared)

 substitute_module (shared)

 suexec_module (shared)

 unique_id_module (shared)

 unixd_module (shared)

 userdir_module (shared)

 version_module (shared)

 vhost_alias_module (shared)

 watchdog_module (shared)

 dav_module (shared)

 dav_fs_module (shared)

 dav_lock_module (shared)

 lua_module (shared)

 mpm_event_module (shared)

 proxy_module (shared)

 lbmethod_bybusyness_module (shared)

 lbmethod_byrequests_module (shared)

 lbmethod_bytraffic_module (shared)

 lbmethod_heartbeat_module (shared)

 proxy_ajp_module (shared)

 proxy_balancer_module (shared)

 proxy_connect_module (shared)

 proxy_express_module (shared)

 proxy_fcgi_module (shared)

 proxy_fdpass_module (shared)

 proxy_ftp_module (shared)

 proxy_http_module (shared)

 proxy_hcheck_module (shared)

 proxy_scgi_module (shared)

 proxy_uwsgi_module (shared)

 proxy_wstunnel_module (shared)

 ssl_module (shared)

 systemd_module (shared)

 cgid_module (shared)

 http2_module (shared)

 proxy_http2_module (shared)

You can see it is quite a vast list and there are many modules that might not be in use on your server. To enable or disable specific modules in Centos 7, we need to visit the module configuration files or more specifically the files located in the /etc/httpd/conf.modules.d/ folder.

Suppose you are using an EC2 instance with Apache server and centos 7. Then you can easily scan all the files in this folder using the following command:

sudo nano /etc/httpd/conf.modules.d/*.conf

If you check out in your Apache main configuration file, /etc/httpd/conf/httpd.conf, you will find this line:

 Include /conf.modules.d/*.conf

Opening this folder using above command will take you to the files contained in the folder.

There are several files included in this folder and you may need to scan all or some of them to find the right location of the module you want to edit.

More specifically, most of the Apache modules are included in the following file:


The modules are loaded in Apache using the LoadModule directive. For example:

LoadModule status_module “modules/mod_status.so”

In the /etc/httpd/conf.modules.d/00-base.conf file, you will see several such directives for loading those modules. The contents of this file which includes most of the modules included with the Apache http server, look like the following:

# This file loads most of the modules included with the Apache HTTP

# Server itself.


LoadModule access_compat_module modules/mod_access_compat.so

LoadModule actions_module modules/mod_actions.so

LoadModule alias_module modules/mod_alias.so

LoadModule allowmethods_module modules/mod_allowmethods.so

LoadModule auth_basic_module modules/mod_auth_basic.so

LoadModule auth_digest_module modules/mod_auth_digest.so

LoadModule authn_anon_module modules/mod_authn_anon.so

LoadModule authn_core_module modules/mod_authn_core.so

LoadModule authn_dbd_module modules/mod_authn_dbd.so

LoadModule authn_dbm_module modules/mod_authn_dbm.so

LoadModule authn_file_module modules/mod_authn_file.so

LoadModule authn_socache_module modules/mod_authn_socache.so

LoadModule authz_core_module modules/mod_authz_core.so

LoadModule authz_dbd_module modules/mod_authz_dbd.so

LoadModule authz_dbm_module modules/mod_authz_dbm.so

LoadModule authz_groupfile_module modules/mod_authz_groupfile.so

LoadModule authz_host_module modules/mod_authz_host.so

LoadModule authz_owner_module modules/mod_authz_owner.so

LoadModule authz_user_module modules/mod_authz_user.so

LoadModule autoindex_module modules/mod_autoindex.so

LoadModule cache_module modules/mod_cache.so

LoadModule cache_disk_module modules/mod_cache_disk.so

LoadModule cache_socache_module modules/mod_cache_socache.so

LoadModule data_module modules/mod_data.so

LoadModule dbd_module modules/mod_dbd.so

LoadModule deflate_module modules/mod_deflate.so

LoadModule dir_module modules/mod_dir.so

LoadModule dir_module modules/mod_dir.so

LoadModule dumpio_module modules/mod_dumpio.so

LoadModule echo_module modules/mod_echo.so

LoadModule env_module modules/mod_env.so

LoadModule expires_module modules/mod_expires.so

LoadModule ext_filter_module modules/mod_ext_filter.so

LoadModule filter_module modules/mod_filter.so

LoadModule headers_module modules/mod_headers.so

LoadModule info_module modules/mod_info.so

LoadModule log_config_module modules/mod_log_config.so

LoadModule logio_module modules/mod_logio.so

LoadModule macro_module modules/mod_macro.so

LoadModule mime_magic_module modules/mod_mime_magic.so

LoadModule mime_module modules/mod_mime.so

LoadModule negotiation_module modules/mod_negotiation.so

LoadModule remoteip_module modules/mod_remoteip.so

LoadModule reqtimeout_module modules/mod_reqtimeout.so

LoadModule request_module modules/mod_request.so

LoadModule rewrite_module modules/mod_rewrite.so

LoadModule setenvif_module modules/mod_setenvif.so

LoadModule slotmem_plain_module modules/mod_slotmem_plain.so

LoadModule slotmem_shm_module modules/mod_slotmem_shm.so

LoadModule socache_dbm_module modules/mod_socache_dbm.so

LoadModule socache_memcache_module modules/mod_socache_memcache.so

LoadModule socache_shmcb_module modules/mod_socache_shmcb.so

LoadModule status_module modules/mod_status.so

LoadModule substitute_module modules/mod_substitute.so

LoadModule suexec_module modules/mod_suexec.so

LoadModule unique_id_module modules/mod_unique_id.so

LoadModule unixd_module modules/mod_unixd.so

LoadModule userdir_module modules/mod_userdir.so

LoadModule version_module modules/mod_version.so

LoadModule vhost_alias_module modules/mod_vhost_alias.so

LoadModule watchdog_module modules/mod_watchdog.so

You can see that it is an exhaustive list and includes most of the modules available with apache server. Now, all you need to do in this file is to comment out the ones you do not need and leave the ones you need uncommented.  For example, in the below list, we have enabled the expires, headers and filter modules, and commented out the rest that we want to disable.

#LoadModule dumpio_module modules/mod_dumpio.so

#LoadModule echo_module modules/mod_echo.so

#LoadModule env_module modules/mod_env.so

LoadModule expires_module modules/mod_expires.so

#LoadModule ext_filter_module modules/mod_ext_filter.so

LoadModule filter_module modules/mod_filter.so

LoadModule headers_module modules/mod_headers.so

In the Apache Server, the MPMs (Multi Processing Modules) including Prefork, Worker and Event can also be loaded as DSO modules using the LoadModule directive.  The MPM modules are listed in a separate file and you can find more about changing MPM modules like Prefork to Worker here.

So, whenever, you are concerned about Apache modules, the relevant folder is /etc/httpd/conf.modules.d/

Some of the modules like proxy modules may be listed in a different file as in the case of AWS EC2 (Amazon Linux2) httpd installation. So, you just need to open this folder and you can check out all the files using

 $ sudo nano /etc/httpd/conf.modules.d/*.conf

Edit the file (comment or uncomment the modules) and then check if Apache syntax is ok using httpd -t.

If syntax is OK, restart httpd so that the changes you made may take effect. Run

$ sudo systemctl restart httpd

Check out the status of Apache server :

$ sudo systemctl status httpd

The output looks like the following when your Apache webserver has successfully restarted and is active:

$ sudo systemctl status httpd

  • httpd.service – The Apache HTTP Server

   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)

   Active: active (running) since Tue 2023-02-28 16:36:22 UTC; 12h ago

  Docs: man:httpd.service(8)

 Main PID: 10773 (httpd)

   Status: “Total requests: 207276; Idle/Busy workers 99/1;Requests/sec: 4.7; Bytes served/sec:  38KB/sec”

   CGroup: /system.slice/httpd.service

        ├─ 9173 /usr/sbin/httpd -DFOREGROUND

        ├─ 9174 /usr/sbin/httpd -DFOREGROUND

        ├─ 9176 /usr/sbin/httpd -DFOREGROUND

        ├─ 9322 /usr/sbin/httpd -DFOREGROUND

        ├─ 9388 /usr/sbin/httpd -DFOREGROUND

        └─10773 /usr/sbin/httpd -DFOREGROUND