Skip to main content
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.

Requirements

From README.md:106:
Older Go versions are not supported. Always use the version specified in the requirements.

Quick Development Build

For rapid development and testing, from README.md:114:
1

Clone the repository

2

Build the binary

This creates a caddy binary in the current directory.
These steps will not embed proper version information. For production builds with version info, see the next section.

Running Tests

From README.md:136:

All Tests

Specific Module

Run tests frequently during development to catch issues early.

Permission to Bind Low Ports

Caddy may need to bind to ports 80 and 443 for HTTPS. From README.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, from README.md:128:
Only do this if you understand the security implications!
Add this line (replace username with your actual username):

Production Build with Version Info

For builds with proper version information and/or plugins, use xcaddy. From README.md:145:
See the xcaddy documentation for detailed information.

Manual Production Build Process

The xcaddy tool automates these steps from README.md:151:
1

Create a new folder

2

Copy main.go

Copy Caddy’s main.go into the folder.From cmd/caddy/main.go:15:
Add imports for any custom plugins you want.
3

Initialize Go module

4

Pin Caddy version (optional)

Replace version with:
  • A git tag (e.g., v2.8.0)
  • A commit hash
  • A branch name (e.g., master)
5

Add plugins (optional)

Add plugin imports to main.go:
6

Build

Build Tags

From README.md:159, the standard build uses these tags:
These tags:
  • nobadger: Exclude BadgerDB support
  • nomysql: Exclude MySQL support
  • nopgx: Exclude PostgreSQL support
These databases are used by certain optional modules. Excluding them reduces binary size.

Custom Version Information

From caddy.go:940, you can set a custom version at build time:
The version is reported in:
  • caddy version command
  • 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
Combine with UPX compression for even smaller binaries:

Static Linking

From README.md:93, Caddy runs with no external dependencies (not even libc):
This creates a fully static binary that can run on any Linux system.

Module Imports

From modules/standard/imports.go:1, standard modules are imported:
The blank imports (_) trigger init() functions that register modules.

Verification

After building, verify your binary:

Troubleshooting

Version Shows “unknown”

From README.md:112, this happens with simple go build. Use xcaddy or manual steps for version info.

Module Not Found

Ensure the module is imported in main.go and run:

Permission Denied on Ports

Run setcap 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