Apache: edit to .conf file produces "Invalid command 'Header'"
Asked Answered
C

2

67

In Magento CE, I'd like to install an add-on to Extendware Page Cache called Lightening Cache.

It requires editing the Apache configuration inside the virtual host definition for the site, by adding:

RewriteEngine On
RewriteMap ewpchash prg:/home/.../shell/extendware/ewpagecache/apache/md5.php

RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{REQUEST_URI} !\.(js|css|png|jpg|jpeg|ico|gif)$ [NC]
RewriteCond %{DOCUMENT_ROOT}%{SCRIPT_FILENAME} !-f
RewriteCond ${ewpchash:%{HTTPS};~;%{HTTP_HOST};~;%{REQUEST_URI};~;%{QUERY_STRING};~;%{HTTP:Cookie};~;%{SCRIPT_FILENAME};~;%{REMOTE_ADDR};~;%{HTTP_USER_AGENT}} -f
RewriteRule ^(.*)$ ${ewpchash:%{HTTPS};~;%{HTTP_HOST};~;%{REQUEST_URI};~;%{QUERY_STRING};~;%{HTTP:Cookie};~;%{SCRIPT_FILENAME};~;%{REMOTE_ADDR};~;%{HTTP_USER_AGENT}} [NC,L]
<FilesMatch "\.(html)$">
     Header unset Cache-Control
     Header unset Expires
     Header append Expires "Thu, 19 Nov 1981 08:52:00 GMT"
     Header append Cache-Control "must-revalidate"
</FilesMatch>

I have added this to the bottom of /etc/apache2/sites-enabled/site.conf.

When I run the command apachectl graceful, I receive the error:

AH00526: Syntax error on line 53 of /etc/apache2/sites-enabled/site.conf: Invalid command 'Header', perhaps misspelled or defined by a module not included in the server configuration Action 'graceful' failed. The Apache error log may have more information.

Site is running Apache 2.4

Have I done something wrong?

Claudy answered 1/1, 2016 at 7:2 Comment(0)
N
135

In order to use Header directive in apache you have to load mod_header module. You can test if module is loaded or not by :-

apache2ctl -M | grep headers_module

find / -name mod_headers.so

If it is loaded you will see something like :-

headers_module (shared)

/usr/lib/apache2/modules/mod_headers.so

If you see no output of find command than load that module directly in your apache conf file. Just append below line :-

LoadModule headers_module modules/mod_headers.so

Note :- mod_header is available as base module in apache. So you don't need to install it explicitly.

Issue following command :-

a2enmod headers

Restart web service

apache2ctl restart

Nisen answered 1/1, 2016 at 8:40 Comment(4)
Great answer ! I had to create a symlink in /etc/apache2/mods-enabled/ directory to load headers_module. cd /etc/apache2/mods-enabled/; ln -s ../mods-available/headers.load headers.load and then restart apache2.Hortensehortensia
+1 - and, for those (who like me) are looking for the mod_headers module in WAMP / WAMPSERVER: The list of available Apache modules doesn't have the "mod_"-prefix. And if you can't edit there, edit the wamp\bin\apache\apache<version\conf\httpd.conf file and comment uncomment the appropriate LoadModule lineAccounting
I have to run on debian: a2enmod headers (that is the name of a module)Malatya
wdupload.kahoindia.in/files/PZSAWVjtEVDNFQTlNp-eYQ/mahesh7pngPatrizius
P
4

If someone is experiencing this error on a dockerized apache, the solution was only add this to my Dockerfile

RUN a2enmod headers

This was the error log:

[Fri Oct 21 17:39:55.384761 2022] [core:alert] [pid 19] [client 172.17.0.1:57480] 
/var/www/html/page1/.htaccess: 
Invalid command 'Header', perhaps misspelled or defined by a module not included in the server configuration

And the error:

enter image description here

And the .htaccess:

Header add X-Custom "Custom Value"

Solution

Here my complete Dockerfile:

FROM php:8.0-apache
RUN a2enmod rewrite
RUN a2enmod headers
COPY src/ /var/www/html
EXPOSE 80

After the fix:

enter image description here

Polity answered 21/10, 2022 at 17:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.