Invalid Command ‘Header’, Perhaps Misspelled or Defined by a Module Not Included in The Server Configuration

When working with the headers in Apache 2 directly, it’s possible to run into this error when you do not have mod_headers enabled. It’s a simple fix: you just need to make sure you enable mod_headers in your configuration.

You can take a shortcut using a2enmod, a command that enables the module for you automatically:

1
2
3
4
5
$ sudo a2enmod headers
 Enabling module headers.
 Run '/etc/init.d/apache2 restart' to activate new configuration!
$ sudo service apache2 restart
 * Restarting web server apache2
$ sudo a2enmod headers
 Enabling module headers.
 Run '/etc/init.d/apache2 restart' to activate new configuration!
$ sudo service apache2 restart
 * Restarting web server apache2

Upon trying the requested page again, you should now be able to use headers within your configuration.

Discussion

Leave a Reply