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
$ sudo a2enmod rewrite cgi$ sudo apache2ctl configtest Syntax OK$ sudo systemctl restart apache2A 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
$ sudo systemctl status apache2 Invalid command 'RewriteEngine', perhaps misspelled or defined by a module not includedin the server configurationNote 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:
| Module | What 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. |
$ sudo a2enmod rewrite cgi headers proxy_http$ sudo apache2ctl configtest$ sudo systemctl restart apache2If Apache still will not start
The error text changes, so read it rather than assuming. Two others are common right after a Koha install:
- 1A port or
ServerNamecollision 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
Address already in use. Something else is on port 80 or 8080.sudo ss -lntp | grep -E ":(80|8080)"names it. - 3A missing
Listenline. 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.
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.
Related
More on installation & setup
Answers to the questions that usually arrive with this one.
MySQL or MariaDB for Koha, and which version
Install MariaDB from your distribution's own repository. Both work — Koha depends on a virtual package that either satisfies — but one of them is what everybody else is running.
Koha packages or a source install: which one you want
Almost every library wants the packages. Here is exactly what a source install gives up — the koha-* commands, the upgrade path, and most published answers — and the two cases where it is still right.
Which Ubuntu or Debian version to install Koha on
The newest Ubuntu LTS or current Debian stable, and nothing else — here is the one command that confirms it before you build the server, and what each other choice actually costs.
apt cannot install koha-common
Unmet dependencies, NO_PUBKEY, or apt claiming the package does not exist. Four causes, in the order they actually occur, with the one command that tells you which of them you have.

