Enable Mod_headers Apache

Page content

How to install mod_headers on Apache Server

The Apache server is an open source and free web server which powers a very large part of the internet. One of the main reasons that the Apache server is highly popular is its modular structure. Apache offers a large number of modules to extend the web server functionality.

The header module is one of those crucial modules used to improve the security and functionality of Apache server.

Basically, the header module provides directives to control and modify http request and response headers, i.e. you can merge, replace or remove headers.

Apart from security, the headers module also plays a crucial role in caching, helping you set cache control headers as well as SEO.

You can easily enable mod_headers (headers module) on the Apache server. Before you can set cache control or other headers in the .htaccess file, you will need to enable the headers module. You must check if the module is already enabled on your server.

To check all the available modules on your apache server, you must run the following command:

$ sudo apache2ctl -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)
 expires_module (shared)
 filter_module (shared)
 mime_module (shared)
 mpm_prefork_module (shared)
 negotiation_module (shared)
 php_module (shared)
 reqtimeout_module (shared)
 rewrite_module (shared)
 setenvif_module (shared)
 socache_shmcb_module (shared)
 ssl_module (shared)
 status_module (shared)

It will output a list of modules that includes the names of all the modules enabled on your server.

If the headers module is not enabled on your server, you can easily enable it.

Enable Mod_Expires Apache Server

Enable mod_headers

You need to run a simple command to enable the headers module on your server.

sudo a2enmod headers

The output will say that the module is now enabled and you need to restart the server to apply the changes.

sudo systemctl restart apache2

That’s all! You have successfully enabled the mod_headers on Apache server.

You can also check out the list of all the enabled modules on your apache server to find if the module has been enabled.

sudo apache2ctl -M

Disable Mod_Headers

Just as you enable the mod_headers on Apache server, you can also disable the headers module easily. Just run the following command in the terminal:

sudo a2dismod headers

The output will tell you that the headers module has been disabled. You can restart the apache server now to apply the changes.

sudo systemctl restart apache2

You have successfully disabled the mod_headers.

You can verify anytime if the headers module is enabled on your server or not by running the following command:

sudo apache2ctl -M | grep headers

If you receive an output like the following, it means the module is enabled.

 headers_module (shared)

Otherwise, it is disabled.

Suggested Reading