Home Arrow Icon Knowledge base Arrow Icon Global Arrow Icon How do I verify if the mod_headers Apache module is enabled


How do I verify if the mod_headers Apache module is enabled


To verify if the mod_headers Apache module is enabled, you can try the following methods:

1. Check using Apache command line tools:

Run one of these commands in the terminal:


apachectl -M | grep headers
apache2ctl -M | grep headers

If mod_headers is enabled, you should see output like:


headers_module (shared)

2. Check phpinfo() output:

Create a PHP file with this content:

php
<?php phpinfo(); ?>

Run it in your browser and search for "Loaded Modules". You should see "mod_headers" listed if it's enabled.

3. Check Apache configuration files:

Look in your Apache configuration files (often in /etc/apache2/ or /etc/httpd/) for a line like:


LoadModule headers_module modules/mod_headers.so

4. Try using mod_headers directives:

Add a mod_headers directive to your .htaccess file or virtual host configuration, like:


Header set X-Test "Test Header"

If it works without errors, mod_headers is enabled.

5. Check enabled modules directory:

On Debian/Ubuntu systems, check if there's a symlink for headers.load in:


/etc/apache2/mods-enabled/

If mod_headers is not enabled, you can enable it with:


sudo a2enmod headers
sudo systemctl restart apache2

These methods should help you verify if mod_headers is enabled on your Apache server. If it's not enabled and you need it, you can enable it using the a2enmod command or by manually adding the LoadModule directive to your Apache configuration.

Citations:
[1] https://ubiq.co/tech-blog/enable-mod_headers-apache-ubuntu/
[2] https://shyammakwana.me/server/2-ways-to-check-for-apache-modules.html
[3] https://github.com/lando/lando/issues/976
[4] https://stackoverflow.com/questions/8794566/how-to-check-mod-headers-and-mod-expires-modules-enabled-in-apache
[5] https://serverfault.com/questions/464319/enabling-mod-headers-on-apache2