TUI for managing sites in Apache Web Server
  • Zig 95.5%
  • Shell 4.2%
  • Dockerfile 0.3%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-11-07 11:39:26 -05:00
doc initial commit 2026-11-05 23:12:05 -05:00
scripts script: make-release-files 2026-11-07 11:39:26 -05:00
src Fix open issues #1-#4 2026-11-07 11:20:44 -05:00
test Add default_site setting for requests matching no site 2026-11-06 00:31:44 -05:00
.gitignore Build apache-sites: TUI editor, rendering, transactional apply 2026-11-06 00:20:51 -05:00
build.zig Build apache-sites: TUI editor, rendering, transactional apply 2026-11-06 00:20:51 -05:00
build.zig.zon Build apache-sites: TUI editor, rendering, transactional apply 2026-11-06 00:20:51 -05:00
CLAUDE.md initial commit 2026-11-05 23:12:05 -05:00
README.md LLM help disclaimer 2026-11-07 11:25:35 -05:00

apache-sites

A terminal UI for managing Apache web site configurations on Ubuntu. Sites are kept in small TOML files under /etc/apache-sites. They are rendered into Apache config and installed only after Apache's own configtest accepts them.

See doc/requirements.md for the requirements this implements.

This application was built with the help of an LLM agent.

Building

Requires Zig 0.17.1.

zig build                 # debug build -> zig-out/bin/apache-sites
zig build test            # unit tests
zig build release         # static binaries:
                          #   zig-out/release/linux-amd64/apache-sites
                          #   zig-out/release/linux-aarch64/apache-sites
test/docker/run.sh        # end-to-end tests against real Apache + PHP-FPM in Docker

Installing

sudo install -m 755 zig-out/release/linux-amd64/apache-sites /usr/local/bin/
sudo apache-sites init    # creates /etc/apache-sites and config.toml
sudo apache-sites         # start the editor

Using the editor

  • Sites list: n new, Enter edit, d delete/undelete, e enable/disable, v view the rendered config, c certificates, s global settings, i system info (interfaces, PHP pools, load problems, last apply log), a apply, u discard all pending changes, q quit.
  • Site form: arrow keys move. Enter or Space edits or toggles a field, ←/→ cycle choices, Ctrl-S/F2 keep the edits as pending changes, Esc goes back, and Ctrl-P/F3 previews the rendered config. Problems with the site are listed live at the bottom. A new site's log file name defaults to the first part of its hostname (wiki for wiki.example.com). AllowOverride offers None, All, or a custom value you type in.
  • Users (shown when Basic auth is on): a add, Enter/p set password, d delete. Passwords are hashed with bcrypt.
  • Settings: edits config.toml (default site, catch-all certificate, certbot directory, ACME webroot, paths, commands, bcrypt cost). Same keys as the site form; Ctrl-S/F2 keeps the edits as pending changes. Commands are edited as one line; quote arguments that contain spaces. The file is rewritten on apply, so comments in it are not kept.
  • Certificates: a pastes in a certificate and then its key, and d removes or restores an unmanaged certificate (one you installed yourself). Let's Encrypt certificates are read-only (manage them with certbot).

Every change is collected into one batch. Nothing touches disk until you apply. Quitting with pending changes asks before discarding them.

What "apply" does

  1. Validates every site and refuses to continue if there are errors.
  2. Renders all enabled sites into /etc/apache-sites/rendered.new/ and installs any newly pasted certificates.
  3. Swaps the new rendered directory into place, keeping the old one. Then it installs /etc/apache2/conf-available/apache-sites.conf, enables it (from conf-enabled, or sites-enabled when default_site = "apache"), and enables any Apache modules the sites need (a2enmod).
  4. Runs apache2ctl configtest. If that fails, every change from steps 2–3 is rolled back and Apache is not reloaded. Your edits stay pending so you can fix them.
  5. Saves config.toml, the site files and password files, removes deleted certificates, and runs systemctl reload apache2.

Command line

apache-sites [--root DIR] [--config-dir DIR] [command]
  edit | list | check | render [HOST] | apply | scan | passwd HOST USER | init

apply, check, and render work on the saved site files, so sites can also be edited by hand. passwd reads the password from stdin.

Files

/etc/apache-sites/
  config.toml              global settings (commands, paths, default_site, acme_webroot, ...)
  sites/<hostname>.toml    one file per site
  passwords/<hostname>.htpasswd
  tls/<name>.crt, <name>.key   unmanaged (manually installed) certificates (key mode 0600)
  rendered/<hostname>.conf     generated Apache config (do not edit)
  rendered/default.d/          the default site, included first
/etc/apache2/conf-available/apache-sites.conf   IncludeOptional of rendered/*.conf

Example site file (every key is optional except hostname):

hostname = "wiki.example.com"
aliases = ["www.wiki.example.com"]
enabled = true
log = "wiki"                      # ${APACHE_LOG_DIR}/wiki.log; "" = no access log
interfaces = ["eth0"]             # [] = all addresses
allow_from = ["192.168.0.0/16"]   # [] = everyone
basic_auth = false
tls = true
cert = ""                         # "" = best match; or "letsencrypt:NAME" / "unmanaged:NAME"
service = "php"                   # static | php | proxy
document_root = "/srv/wiki"
directory_index = "index.php index.html"
allow_override = "None"
php_version = "8.5"
php_user = "dokuwiki"
proxy_url = ""
proxy_nocanon = false
allow_encoded_slashes = "off"     # off | on | nodecode
proxy_websockets = false
proxy_preserve_host = false
raw = '''
Header set X-Frame-Options "SAMEORIGIN"
'''

Notes and behaviours worth knowing

  • Interfaces. Sites name interfaces (eth0), not addresses. They are turned into the interface's current IPv4/IPv6 addresses each time you apply, so re-apply after an address changes. Link-local IPv6 is skipped. A site set to "all addresses" also lists the specific addresses used by interface-bound sites. Otherwise Apache would never match it on those addresses.
  • Default site. Apache sends a request whose hostname matches no site (a bare IP, a stray DNS name, a scanner) to the first vhost it loaded for that address:port. Ubuntu loads conf-enabled/ before sites-enabled/, so without intervention that would be the alphabetically first apache-sites site. default_site in config.toml controls this:
    • "reject" (default): a catch-all vhost in rendered/default.d/, loaded before every site, answers 421 Misdirected Request on every address and port our sites use. Port 443 uses Ubuntu's snakeoil certificate (default_cert/default_key; needs the ssl-cert package).
    • "<hostname>": that site is rendered into default.d/ so it loads first and becomes the default wherever it listens.
    • "apache": Apache's own default (000-default) stays in charge. The include file stays in conf-available but is enabled as sites-enabled/zzz-apache-sites.conf instead of from conf-enabled, so it loads after your other sites. This doesn't cover addresses that interface-bound sites listen on (a warning says so).
    • "none": no handling; the alphabetically first site wins (warns).
  • Certificates. TLS defaults to on for a new site when a certificate matches its hostname, exactly or by wildcard. Pasted keys must be unencrypted. A certificate that doesn't match its key is caught by Apache's configtest.
  • certbot. Port 80 of a TLS site is a plain redirect to HTTPS. If you renew with certbot certonly --webroot -w DIR, set acme_webroot = "DIR" in config.toml. Port 80 then serves /.well-known/acme-challenge/ from there instead of redirecting it.
  • Logging. An empty log name disables access logging. Errors still go to Apache's global error log.
  • WebSockets use ProxyPass ... upgrade=websocket (Apache 2.4.47+).

Development

test/make-fixture.sh DIR builds a fake filesystem root with PHP pools, a self-signed "Let's Encrypt" cert, and a config that replaces the Apache commands with harmless ones. Then run zig-out/bin/apache-sites --root DIR to try the editor without touching the host's Apache.

Source layout: src/toml.zig (TOML subset), site.zig (data model), scan.zig (PHP pools, certificates, interfaces), render.zig (validation and Apache rendering), state.zig (editing session), apply.zig (transactional apply), htpasswd.zig, and tui/ (terminal layer, widgets, app).