Building Caddy from source gives you control over the build process and is essential for module development. This guide covers building for both development and production.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/caddyserver/caddy/llms.txt
Use this file to discover all available pages before exploring further.
Requirements
FromREADME.md:106:
Quick Development Build
For rapid development and testing, fromREADME.md:114:
These steps will not embed proper version information. For production builds with version info, see the next section.
Running Tests
FromREADME.md:136:
All Tests
Specific Module
Permission to Bind Low Ports
Caddy may need to bind to ports 80 and 443 for HTTPS. FromREADME.md:120:
Linux
Using go run
If you prefer go run, use the included helper script:
Passwordless setcap (Optional)
To avoid entering your password repeatedly, fromREADME.md:128:
username with your actual username):
Production Build with Version Info
For builds with proper version information and/or plugins, use xcaddy. FromREADME.md:145:
Manual Production Build Process
The xcaddy tool automates these steps fromREADME.md:151:
Copy main.go
Copy Caddy’s main.go into the folder.From Add imports for any custom plugins you want.
cmd/caddy/main.go:15:Pin Caddy version (optional)
version with:- A git tag (e.g.,
v2.8.0) - A commit hash
- A branch name (e.g.,
master)
Build Tags
FromREADME.md:159, the standard build uses these tags:
nobadger: Exclude BadgerDB supportnomysql: Exclude MySQL supportnopgx: Exclude PostgreSQL support
These databases are used by certain optional modules. Excluding them reduces binary size.
Custom Version Information
Fromcaddy.go:940, you can set a custom version at build time:
caddy versioncommand- Admin API responses
- Server headers (if configured)
Build Output Location
By default,go build creates the binary in the current directory:
Cross-Compilation
Build for different platforms:Optimizing Binary Size
Reduce binary size with build flags:-s: Strip symbol table-w: Strip DWARF debugging info-trimpath: Remove file system paths from binary
Static Linking
FromREADME.md:93, Caddy runs with no external dependencies (not even libc):
Module Imports
Frommodules/standard/imports.go:1, standard modules are imported:
_) trigger init() functions that register modules.
Verification
After building, verify your binary:Troubleshooting
Version Shows “unknown”
FromREADME.md:112, this happens with simple go build. Use xcaddy or manual steps for version info.
Module Not Found
Ensure the module is imported inmain.go and run:
Permission Denied on Ports
Runsetcap on the binary (Linux) or use sudo.
Large Binary Size
Use optimization flags and consider excluding unused modules.Next Steps
xcaddy Tool
Use xcaddy for easier builds with plugins
Custom Builds
Create custom builds with plugins
Module Development
Develop your own modules
Testing Guide
Test your custom builds