How to Install Caddy Server

Caddy is a powerful, enterprise-ready, open-source web server with automatic HTTPS written in Go. Installing Caddy server is straightforward due to its simplicity and the fact that it has no dependencies. This guide will walk you through the installation process on various operating systems.

Prerequisites

Before installing Caddy, ensure you have:

  • A server or local machine running Linux, macOS, or Windows.

  • Administrative or root access on the machine.

  • Basic knowledge of terminal or command line usage.

Installation on Linux

Using Official Repository

  1. Import the Caddy repository GPG key:

   curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo tee /etc/apt/trusted.gpg.d/caddy-stable.asc
  1. Add the repository:

   curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-stable.list
  1. Update the package list and install Caddy:

   sudo apt update   sudo apt install caddy

Using Snap Package

Alternatively, you can install Caddy via Snap:

sudo snap install caddy --classic

Installation on macOS

Using Homebrew

The easiest way to install Caddy on macOS is using Homebrew:

brew install caddy

Installation on Windows

Using Scoop

Windows users can install Caddy using Scoop, a command-line installer:

  1. Install Scoop (if not already installed):

   Set-ExecutionPolicy RemoteSigned -scope CurrentUser   iwr -useb get.scoop.sh | iex
  1. Install Caddy:

   scoop install caddy

Manual Installation

  1. Download the latest Caddy binary from the official Caddy website.

  2. Extract the downloaded file to a directory of your choice.

  3. Add the directory where you extracted Caddy to your system's PATH.

Verifying the Installation

To verify that Caddy is installed correctly, run:

caddy version

This command should return the installed version of Caddy.

Configuring Caddy

After installation, you can start configuring Caddy by creating a Caddyfile in the directory where you want to serve files or proxy requests. Here's a simple example that serves static files:

:80 {    root * /var/www    file_server}

Save this configuration in a file named Caddyfile and run Caddy in the same directory:

caddy run

Caddy will start serving the contents of /var/www on port 80.

Conclusion

You have successfully installed Caddy on your system. You can now explore further configurations and utilize Caddy's full potential to serve your web applications securely and efficiently. For more detailed configurations and advanced usage, refer to the official Caddy documentation.



Still need help?

Contact us

General