Install Caddy Web Server on Debian 11/Debian 10

Today you will learn how to install Caddy Web Server on Debian 11/Debian 10. Caddy is a powerful and open-source web server written in Go.

Install Caddy Web Server on Debian 11/Debian 10

You can install Caddy Web Server on Debian 11/Debian 10 through Docker, from official repositories or by compiling from source.

This tutorial will demonstrate how to install Caddy Web Server on Ubuntu 22.04 using the official repositories.

Install Caddy Web Server on Debian 11/Debian 10 using the official repositories

Install GPG key for Caddy repository

sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https curl
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' \
> /etc/apt/trusted.gpg.d/caddy-stable.asc

Add Caddy package to Debian

curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' \
> /etc/apt/sources.list.d/caddy-stable.list

Update system packages again

sudo apt update

Now install Caddy Web Server on Debian 11/Debian 10

sudo apt install caddy

Check if Caddy is installed

caddy version

Caddy web server runs automatically after installation. Check the status of Caddy

sudo systemctl status caddy

Stop, restart, enable, start and reload caddy by running the command:

sudo systemctl [start|stop|restart|reload|enable|disable] caddy

Test Caddy Web Server

Visit your browser and type in localhost or your IP address. The page should load as below:

You have managed to install Caddy Web Server on Debian 11/Debian 10.

Serving your site using Caddy Web Server

Create a directory under /var/www/html/caddy to store your site files

sudo mkdir -p /var/www/html/caddy

Assign the directory and its files to caddy group:

sudo chown -R caddy:caddy /var/www/html/caddy

Now create a simple HTML named index.html under you website directory i.e /var/www/html/caddy

sudo gedit /var/www/html/caddy/index.html

Copy the content below into the file and save it.

<!DOCTYPE html>
<html>
<head>
<title>Hello from Caddy!</title>
</head>
<body>
<p style="font-family: sans-serif">
This page tests that Caddy Web Server works. Congratulations, It works! </p>
<h2>Thank you for visiting Itnixpro.com</h2>
</body>
</html>

Configure the Caddyfile

Open the Caddyfile configuration file you created earlier for editing:

sudo gedit /etc/caddy/Caddyfile

Add the following lines, replacing localhost with the domain name of your site

localhost {
    root * /var/www/html/caddy
    encode gzip
    file_server 
}

This file tells Caddy to direct all HTTP traffic to your server and be served with files (file_server) from /var/www/html/caddy and compressed using gzip to reduce page loading times on the client side.

If you have your site in a different directory, specify the path the that directory by replacing /var/www/html/caddy with the correct path.

Reload the restart Caddy Web server:

sudo systemctl reload caddy

Visit your browser and type in a new tab: localhost

The page opens:

You can also setup you site using a database server and a CMS like WordPress, Drupal etc.

Note: Ensure you reload Caddy every time you make changes to the Caddyfile file.

Conclusion

You have reached the end on how to install Caddy Web Server on Ubuntu 22.04.

Find more on Caddy Server official website and look for tutorials of using Caddy Web Server in Caddy Web Server documentation.

More tutorials

Install DHCP Server on Debian 11

Setup NTP Server on Debian 11

Install and Configure VNC server on Debian 11

Install NFS Server on Debian 11

Android Developer | Linux | Technical Writer | Backend Developer

Leave a Comment