Koha Solutions

Installation & setup

Apache will not start: Invalid command 'RewriteEngine'

Apache refuses to start after enabling a Koha site because mod_rewrite is not enabled. One command fixes it — and the same class of error covers the other three modules Koha needs.

Updated 2026-08-12 · Tested against Koha 26.05

Apache is reading RewriteEngine On in Koha's site file and does not know the directive, because mod_rewrite is not enabled. Enable it and the CGI module, test the configuration, and reload — three commands, and nothing in Koha itself needs changing.

Step 1Enable the modules and reload

Terminal
$ sudo a2enmod rewrite cgi$ sudo apache2ctl configtest Syntax OK$ sudo systemctl restart apache2

A restart rather than a reload: enabling a module loads new code into the server, which a graceful reload does not do. configtest before either one, every time — Apache refuses to start on a bad config, so an untested edit on a live server takes the OPAC down along with the staff interface.

The exact error, and where it appears

Terminal
$ sudo systemctl status apache2 Invalid command 'RewriteEngine', perhaps misspelled or defined by a module not includedin the server configuration

Note that this is a startup failure, not a page error. Apache parses every enabled site file before it binds a port, so one unknown directive in Koha's site file stops the whole web server — including any other site on the same machine. That is why it usually appears immediately after a2ensite and never before it.

The other modules Koha needs

Each missing module produces its own version of the same error, and they are easier to fix together than one at a time:

ModuleWhat it is for, and what breaks without it
<code>rewrite</code>The clean URLs both virtual hosts use. Without it Apache will not start at all.
<code>cgi</code>Runs Koha's Perl scripts. Without it pages download as files or 500.
<code>headers</code>, <code>proxy_http</code>Required only when Plack is enabled — Apache proxies to it. Missing, the site returns 502 or 503.
<code>ssl</code>Required for an HTTPS site, including koha-create --letsencrypt.
Terminal
$ sudo a2enmod rewrite cgi headers proxy_http$ sudo apache2ctl configtest$ sudo systemctl restart apache2

If Apache still will not start

The error text changes, so read it rather than assuming. Two others are common right after a Koha install:

  1. 1A port or ServerName collision with the default site. Disable it: sudo a2dissite 000-default, then restart. Two virtual hosts claiming the same name on the same port is a warning rather than a failure, but it means requests reach the wrong one.
  2. 2Address already in use. Something else is on port 80 or 8080. sudo ss -lntp | grep -E ":(80|8080)" names it.
  3. 3A missing Listen line. Not a startup failure — Apache starts and the staff port simply never answers. That is Koha, Apache and port 8080.

Why the packages do not enable it for you

They try to. koha-create runs a2enmod rewrite and a2enmod cgi as part of building an instance, so a plain package install on a clean server does not hit this at all.

It appears when the site file arrives some other way: a configuration copied from another server, a virtual host written by hand, an instance restored onto a rebuilt machine, or an Apache installed after Koha. In each of those the site file exists without the step that enabled the modules ever having run, and Apache only finds out at its next start — which can be days later, at a reboot, and therefore looks unrelated to whatever was changed.

That delay is the practical lesson: run apache2ctl configtest after any change to a site file, not at the next restart. It is the difference between a typo and an outage that begins during a power cut.

If Apache starts cleanly and Koha still returns an error page, the fault has moved into Koha and the message will be in the instance log — see finding the line that caused a Koha internal server error.

Share this article

Would rather not do this yourself? We do it as a service — and if you would rather it were already done, it is on Koha Cloud before you log in.