DebianDebian Based

How To Install Caddy on Debian 12

Install Caddy on Debian 12

In this tutorial, we will show you how to install Caddy on Debian 12. Caddy is a powerful, lightweight, and easy-to-use web server that has gained popularity among developers and system administrators. It offers a range of features, including automatic HTTPS, HTTP/2 support, and a simple configuration syntax.

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 the step-by-step installation of the Caddy web server on a Debian 12 (Bookworm).


Before proceeding with the installation of Caddy on Debian 12, ensure you meet the following requirements:

  • A server running one of the following operating systems: Debian 12 (Bookworm).
  • It’s recommended that you use a fresh OS install to prevent any potential issues.
  • SSH access to the server (or just open Terminal if you’re on a desktop).
  • An active internet connection. You’ll need an internet connection to download the necessary packages and dependencies for the Caddy web server.
  • A user account with sudo privileges to execute administrative commands.

Install Caddy on Debian 12 Bookworm

Step 1. To begin, we need to update the package index and install a few essential dependencies. Open your terminal and run the following commands:

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

These commands will refresh the package list and install the necessary tools for adding the Caddy repository and managing HTTPS connections.

Step 2. Installing Caddy on Debian 12.

Next, we’ll add the official Caddy repository to our system. This ensures that we have access to the latest version of Caddy and can easily update it in the future. Follow these steps:

sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https curl
curl -1sLf '' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
curl -1sLf '' | sudo tee /etc/apt/sources.list.d/caddy-stable.list

Update the package index to recognize the new repository:

sudo apt update

With the repository added, we can now install Caddy using the APT package manager. Run the following command:

sudo apt install caddy

Once the installation is complete, you can verify that Caddy is installed correctly by checking its version:

caddy version

Step 3. Configuring Caddy.

Caddy uses a configuration file called Caddyfile to define how it should serve your website. Let’s create a basic Caddyfile to serve a static site:

sudo mkdir /var/www/

Create an index.html file inside the directory:

echo "Hello, World!" | sudo tee /var/www/

Open a new Caddyfile using a text editor (e.g., nano):

sudo nano /etc/caddy/Caddyfile

Add the following content to the Caddyfile: {
    root * /var/www/

Save the file and start Caddy:

sudo systemctl start caddy

Test your configuration by accessing in your web browser. You should see the “Hello, World!” message.

Step 4. Enabling PHP Support (Optional).

If your website requires PHP support, you can easily configure Caddy to work with PHP-FPM. Follow these steps:

sudo apt install php php-fpm

Configure PHP-FPM to listen on a Unix socket:

sudo nano /etc/php/8.3/fpm/pool.d/www.conf

Find the listen directive and change it to:

listen = /run/php/php8.1-fpm.sock

Save the file, then restart PHP-FPM:

sudo systemctl restart php8.3-fpm

Modify the Caddyfile to handle PHP requests: {
    root * /var/www/
    php_fastcgi unix//run/php/php8.3-fpm.sock

This configuration tells Caddy to pass PHP requests to the PHP-FPM Unix socket.

Finally, restart Caddy:

sudo systemctl restart caddy

Congratulations! You have successfully installed Caddy. Thanks for using this tutorial to install the latest version of the Caddy web server on Debian 12 Bookworm. 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!


r00t is a seasoned Linux system administrator with a wealth of experience in the field. Known for his contributions to, r00t has authored numerous tutorials and guides, helping users navigate the complexities of Linux systems. His expertise spans across various Linux distributions, including Ubuntu, CentOS, and Debian. r00t's work is characterized by his ability to simplify complex concepts, making Linux more accessible to users of all skill levels. His dedication to the Linux community and his commitment to sharing knowledge makes him a respected figure in the field.
Back to top button