How To Install Caddy on Debian 11

Install Caddy on Debian 11

In this tutorial, we will show you how to install Caddy on Debian 11. For those of you who didn’t know, Caddy is a powerful, enterprise-ready, open-source web server with automatic HTTPS written in Go. It is designed with security in mind and provides a number of features that are useful for hosting websites. Caddy is compatible with Operating Systems such as Linux, BSD, Windows, Mac, Solaris, and Android platforms.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo‘ to the commands to get root privileges. I will show you through the step-by-step installation of the Caddy Web Server on a Debian 11 (Bullseye).

Install Caddy on Debian 11 Bullseye

Step 1. Before we install any software, it’s important to make sure your system is up to date by running the following apt commands in the terminal:

sudo apt update
sudo apt upgrade
sudo apt install curl debian-keyring debian-archive-keyring apt-transport-https

Step 2. Installing Caddy on Debian 11.

By default, the Caddy package is not available on the Debian 11 base repository. Now run the following command to add the Caddy repository to your Debian system:

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

Next, import the GPG key:

curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | apt-key add -

Now, update the Debian package lists and install Caddy by running the command below:

sudo apt update 
sudo apt install caddy

Then, run the commands below to stop, start and enable the Caddy service to always start up with the server boots:

sudo systemctl stop caddy
sudo systemctl start caddy
sudo systemctl enable caddy

Verify the Caddy installation using the following command:

caddy version

Step 3. Enable PHP Support on Caddy.

Now we install PHP and other necessary extensions using the following command below:

sudo apt install php-fpm php-mysql php-curl php-gd php-mbstring php-common php-xml php-xmlrpc

Next, edit the PHP-FPM configuration file and change the default user and group with caddy:

nano /etc/php/7.4/fpm/pool.d/www.conf

Find and replace:

user = caddy
group = caddy
listen.owner = caddy
listen.group = caddy

Save and close the file, then restart the PHP-FPM service to apply the changes:

sudo systemctl restart php7.4-fpm

Step 4. Create Virtual Host Caddy.

Now edit the /etc/caddy/Caddyfile file with the following command below:

nano /etc/caddy/Caddyfile

Add the following line:

caddy.your-domain.com:80 {
    root * /usr/share/caddy/
    encode gzip zstd
    php_fastcgi unix//run/php/php7.4-fpm.sock
}

Save and close the file, then restart the Caddy service to apply the changes:

sudo systemctl restart caddy

Step 5. Accessing Caddy Web Interface.

Once successfully installed, open your browser and search for your server IP or domain name:

http://caddy.your-domain.com

Congratulations! You have successfully installed Caddy. Thanks for using this tutorial for installing the latest version of Caddy  Web Server on Debian 11 Bullseye. For additional help or useful information, we recommend you check the official Caddy website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!