Building Caddy Server From Source

Caddy recently changed their pricing and licensing, which ultimately lead to quite a few upset users. For example, I recently received an email from a student of my course (Web Development with Go) who asked if I was going to redo my deployment videos and remove Caddy from them because he would never be using Caddy again after the license change.

While I don’t want to get into a debate about the changes made by Caddy, what I do want to say is that the source code is still free, open source software licensed under the Apache 2.0 license - https://github.com/mholt/caddy/blob/master/LICENSE.txt

What that means is that all of the changes - the EULA attached to the binaries, and the Caddy-Sponsors header required for the personal license, and the non-commercial aspect of the license - all only apply if you download a binary provided by the Caddy team.

If you don’t agree with those changes, or maybe you simply can’t afford the pricing, an alternative option is to simply build Caddy from source and use it that way. In this post I am going to walk you through how to do that because it is incredibly simple to do. In fact, it is so simple you can see it done in about 30s in the sped up gif below.

Building Caddy from source

I hope that after seeing how easy it is that many of you will take a step back before throwing rocks and instead spend a few minutes evaluating whether this change actually has a massive negative impact on you. Matt and everyone else involved with Caddy could have changed the license of the source code for Caddy, but they didn’t. It is still open source, and despite not agreeing with all the other changes I do respect them for writing a great piece of software and keeping it open source.

Install Go

To start, we need to install Go. If you haven’t done so already, I suggest checking out the official docs here: https://golang.org/doc/install

Alternatively, you could likely do this with Docker but I won’t cover that here.

Get the source and remove the Caddy-Sponsors header

Next we are going to get the source for caddy and remove the Caddy-Sponsors header that many people were against. We will need to grab both mholt/caddy as well as the caddyserver/builds package, and I suggest using the -u flag to ensure you have an updated version.

cd $GOPATH/src
go get -u github.com/mholt/caddy
go get -u github.com/caddyserver/builds

Next we are going to remove the sponsors header.

# Use your editor of choice
cd $GOPATH/src/github.com/mholt/caddy
atom caddyhttp/httpserver/server.go

Find the lines that read:

sponsors := "Minio, Uptime Robot, and Sourcegraph"
w.Header().Set("Caddy-Sponsors", "This free web server is made possible by its sponsors: "+sponsors)

At the time of this writing they could be found at lines 346 and 347.

Comment those both out. As far as I can tell these are the only lines you need to change to remove the header. You can also remove th “Server” header if you wish - it is just above these lines of code.

Save your source code then head back to the terminal. We are now ready to build caddy.

cd $GOPATH/src/github.com/mholt/caddy/caddy

# For most linux distros:
go run build.go -goos=linux -goarch=amd64

# For most mac OS computers:
go run build.go -goos=darwin

After building you should have a binary in your current directory named caddy. Congrats, you have successfully built Caddy from scratch!

Did you enjoy this article? Join my mailing list!

If you enjoyed this article, please consider joining my mailing list.

I will send you roughly one email every week letting you know about new articles (like this one) or screencasts (ex) that I am working on or have published recently. No spam. No selling your emails. Nothing shady - I’ll treat your inbox like it was my own.

As a special thank you for joining, I’ll also send you both screencast and ebook samples from my course, Web Development with Go.

Learn Web Development with Go!

Sign up for my mailing list and I'll send you a FREE sample from my course - Web Development with Go. The sample includes 19 screencasts and the first few chapters from the book.

You will also receive emails from me about Go coding techniques, upcoming courses (including FREE ones), and course discounts.

Avatar of Jon Calhoun
Written by
Jon Calhoun

Jon Calhoun is a full stack web developer who teaches about Go, web development, algorithms, and anything programming. If you haven't already, you should totally check out his Go courses.

Previously, Jon worked at several statups including co-founding EasyPost, a shipping API used by several fortune 500 companies. Prior to that Jon worked at Google, competed at world finals in programming competitions, and has been programming since he was a child.

Related articles

Spread the word

Did you find this page helpful? Let others know about it!

Sharing helps me continue to create both free and premium Go resources.

Want to discuss the article?

See something that is wrong, think this article could be improved, or just want to say thanks? I'd love to hear what you have to say!

You can reach me via email or via twitter.

Recent Articles All Articles Mini-Series Progress Updates Tags About Me Go Courses

©2024 Jonathan Calhoun. All rights reserved.