DEV Community

Cover image for Install Caddy on Ubuntu 22.04 - HostnExtra
HostnExtra Technologies
HostnExtra Technologies

Posted on

Install Caddy on Ubuntu 22.04 - HostnExtra

In this article, we’ll explain you how to install Caddy on Ubuntu 22.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.

Prerequisites

  • A Ubuntu install dedicated server or KVM VPS.
  • A root user access or normal user with administrative privileges.

Install Caddy on Ubuntu 22.04

1. Keep the server up to date

# apt update -y && apt upgrade -y

WWWW2. Install Caddy

Following command will install and automatically starts and runs Caddy for you as a systemd service named caddy using our official caddy.service unit file.

Install dependencies:

# sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https

First, add GPG key using following command:

# curl -1sLf ‘https://dl.cloudsmith.io/public/caddy/stable/gpg.key’ | sudo gpg –dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
Enter fullscreen mode Exit fullscreen mode

Next, add repository and update it:

# curl -1sLf ‘https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt’ | sudo tee /etc/apt/sources.list.d/caddy-stable.list
Enter fullscreen mode Exit fullscreen mode

# apt update

Finally, install Caddy using following command:

# apt install caddy

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

http://Server-IP

OR

http://example.com

Install Caddy on Ubuntu

3. Configure Domain with Caddy

Before moving following, first set up domain’s A/AAAA DNS record at your registrar or control panel.

Note: Replace hostnextra.com with your domain name

Create a directory for your website files

# mkdir -p /var/www/html/hostnextra.com

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/hostnextra.com -R
# chcon -t httpd_sys_rw_content_t /var/www/html/hostnextra.com -R
Enter fullscreen mode Exit fullscreen mode

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

# nano /etc/caddy/Caddyfile

Change the site root to /var/www/html/hostnextra.com (write your website path) as

install Caddy HostnExtra

Note:

If you want to use SSL, you need to mention :443 SSL port and also install SSL certificate.

You can run caddy trust command to install SSL local certificate. We’ve not tested it yet. If we perform it in future, we’ll update the tutorial. You can check the official document about Automatic HTTPS for more information.

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/hostnextra.com 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/hostnextra.com/index.html
Enter fullscreen mode Exit fullscreen mode

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 22.04.

Top comments (0)