UbuntuUbuntu Based

How To Install Caddy on Ubuntu 22.04 LTS

Install Caddy on Ubuntu 22.04

In this tutorial, we will show you how to install Caddy on Ubuntu 22.04 LTS. For those of you who didn’t know, Caddy is a powerful open-source web server written in Go. It has great security features with automatic HTTPS and fast than other web servers utilizing the power of CPUs.

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 Ubuntu 22.04 (Jammy Jellyfish). You can follow the same instructions for Ubuntu 22.04 and any other Debian-based distribution like Linux Mint, Elementary OS, Pop!_OS, and more as well.

Prerequisites

  • A server running one of the following operating systems: Ubuntu 22.04, 20.04, and any other Debian-based distribution like Linux Mint.
  • 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).
  • A non-root sudo user or access to the root user. We recommend acting as a non-root sudo user, however, as you can harm your system if you’re not careful when acting as the root.

Install Caddy on Ubuntu 22.04 LTS Jammy Jellyfish

Step 1. First, make sure that all your system packages are up-to-date by running the following apt commands in the terminal.

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

Step 2. Installing Caddy Web Server on Ubuntu 22.04.

By default, Caddy is not available on Ubuntu 22.04 base repository. Now run the following command below to add the Caddy repository to your Ubuntu system:

curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo 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' | sudo tee /etc/apt/trusted.gpg.d/caddy-stable.asc

After the repository is enabled, now install the latest version of Caddy using the below command:

sudo apt update
sudo apt install caddy

After successfully installation, enable Caddy (to start automatically upon system boot), start, and verify the status using the commands below:

sudo systemctl enable caddy
sudo systemctl start caddy
sudo systemctl status caddy

You can confirm the Caddy build version with the below command:

caddy version

Step 3. Configure Caddy.

By default Caddy configuration file is located at /etc/caddy/Caddyfile. Now we run the commands below to open the Caddy default configuration file:

sudo nano /etc/caddy/Caddyfile

Add the following lines:

http://.your-domain.com {
    root * /var/www/html
    encode gzip
    file_server
}

Save and close the file, then restart the Caddy Web server using the following command:

sudo systemctl restart caddy

Step 4. Configure Firewall.

If you are using UFW (Uncomplicated Firewall), you need to configure it to allow access to HTTP and HTTPS ports for the server to work:

sudo ufw allow http
sudo ufw allow https

Step 5. Accessing Caddy Web Server.

Once successfully installed, open a web browser on your system and type the server’s IP in the address bar. You will get the default Caddy server page:

Install Caddy on Ubuntu 22.04 LTS Jammy Jellyfish

Step 6. Enable PHP Support on Caddy.

First, 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

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

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

Find and replace user and group name from www-data to caddy:

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 php8.1-fpm

Congratulations! You have successfully installed Caddy. Thanks for using this tutorial for installing the Caddy web server on Ubuntu 22.04 LTS Jammy Jellyfish system. 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

r00t is a seasoned Linux system administrator with a wealth of experience in the field. Known for his contributions to idroot.us, 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