Architecture
How Anvil serves local sites: a request goes from the browser through Anvil's DNS and Caddy to PHP-FPM, static files or an app's dev server.
browser ──▶ Anvil DNS (*.test → 127.0.0.1)
──▶ ports 80/443, forwarded by pf to 8080/8443 (optional)
──▶ Caddy (HTTP, HTTPS per application, local certificates, loopback only)
├─▶ PHP-FPM: a pool per PHP version; own pools for custom php.ini, worktrees
├─▶ static files
└─▶ app dev servers on private ports (Node.js, Rust, Go, .NET, Python)
services (MySQL, PostgreSQL, Redis, Mailpit, S3 storage) ◀── your applications, 127.0.0.1 onlyThis is macOS. On Windows, Caddy listens on 80 and 443 itself, DNS is on port 53
behind a Name Resolution Policy rule, and PHP runs as php-cgi pools. On Linux,
for now, applications answer at <name>.localhost:8080, with no DNS step, port
forwarding or certificate trust.
Pieces
- DNS. Built into Anvil, on 127.0.0.1:5354 by default. It answers
127.0.0.1for every name under the suffix and refuses the rest./etc/resolver/testscopes it to*.test. - Caddy, downloaded into
~/.anvil/bin. Anvil generates~/.anvil/run/Caddyfilewith one block per application: files plus PHP-FPM, or a proxy to the dev server. For HTTPS applications, Caddy issues certificates from its local CA and redirectshttp://. Dotfiles are never served. - PHP-FPM. One shared pool per PHP version in use. Applications with their own php.ini values, and each worktree, get a dedicated pool, so settings and environment don't leak.
- Application dev servers (Node.js, Rust, Go, .NET, Python) run with the
toolchain from
~/.anvil/runtimes. Each gets a private port in$PORTand its own process group, so its children stop with it. - Services run separately from the web server, so application changes never restart a database. Each has its own port, data folder, log and pid file.
Supervision
anvil start (or the app) runs everything as child processes, with pids in
~/.anvil/run. Leftovers from a killed Anvil are cleaned up on the next start.
Stop sends SIGTERM, then SIGKILL after a grace period. See
Configuration for ~/.anvil.