How to Install Caddy on Ubuntu 20.04

How to Install Caddy on Ubuntu 20.04

In this article, we’ll explain you how to install Caddy on Ubuntu 20.04. This article will guide you with the installation process and host a website.

The Caddy web server is an open-source web server written in Go. It is designed around simplicity and security that comes with a number of features that are useful for hosting websites. Caddy is both a flexible, efficient static file server and a powerful, scalable reverse proxy.


Install Caddy on Ubuntu 20.04

1. Keep the server up to date

# apt update -y && apt upgrade -y

2. Install Caddy

First, add GPG key using following command:

# curl -1sLf ‘' | sudo apt-key add -

Next, add repository and update it:

# curl -1sLf ‘' | sudo tee -a /etc/apt/sources.list.d/caddy-stable.list

# apt update

Finally, install Caddy using following command:

# apt install caddy

Now, navigate to your browser and enter your server IP or domain name:



3. Configure Domain with Caddy

Note: Replace with your domain name

Create a directory for your website files

# mkdir -p /var/www/html/

Next, if you are using SELinux than you need to change the file security context for web content. (Optional)

# chcon -t httpd_sys_content_t /var/www/html/ -R
# chcon -t httpd_sys_rw_content_t /var/www/html/ -R

Now, open Caddy’s configuration file and add your domain name and change website’s root directory.

# vi /etc/caddy/Caddyfile

Replace :80 with your domain name and change the site root to /var/www/html/ as

Once you done with the changes reload the caddy.service to reflect the changes.

# systemctl reload caddy

Now, create a index.html file in /var/www/html/ using following command:

# echo ‘<!doctype html><head><title>Hello from Caddy!</title></head><body><h1 style=”font-family: sans-serif”>This page is being served via Caddy</h1></body></html>’ | sudo tee /var/www/html/

Finally, refresh the page in your browser and you will see our newly created index.html.

In this article, we have seen how to install Caddy on Ubuntu 20.04.

HostnExtra was founded in 2016. All of our servers are located in the continental United States and United Kingdom. View more details