Site icon VPS Windows

Step-by-Step Guide to Install Caddy on Ubuntu VPS

Install-Caddy-on-Ubuntu-VPS

Install-Caddy-on-Ubuntu-VPS

install caddy

Caddy is an open-source web server built with the Go programming language, known for its ability to automatically issue free SSL certificates from Let’s Encrypt. If you’re looking for a simple and efficient solution to deploy your website on an Ubuntu VPS, Caddy is definitely a worthwhile option to consider. In this article, VPSWindows will provide you with a detailed, easy-to-follow guide on how to install Caddy on Ubuntu VPS.

What is Caddy and Why use it?

Caddy is an open-source web server written in the Go programming language. It is designed with the philosophy that “simplicity is best”, focusing on automating complex tasks that traditional web servers like Nginx or Apache typically require manual configuration for.

Top Benefits of Using Caddy:

System Requirements and Preparation Before Installation

Before installing Caddy on your Ubuntu VPS, make sure your system meets the basic requirements. These prerequisites will help ensure a smooth and efficient installation process.

SSH Access to Your VPS

To install Caddy, you need SSH access to your VPS. This access is essential not only for the installation process but also for effectively managing your server. To check your SSH connection, open the terminal on your local machine and run the following command:
ssh username@your_vps_ip
If you can connect successfully, you’re ready to move on.

Sudo Privileges or Root Access

Having sudo privileges or root access is essential when you install Caddy on Ubuntu VPS. This allows you to execute commands that require elevated permissions to modify system configurations or install software.

Your Domain Must Point to Your VPS IP Address

This is one of the most important requirements for Caddy to automatically issue HTTPS certificates. Your domain (e.g., yourdomain.com or www.yourdomain.com) must have a DNS A record pointing to the public IP address of your VPS. This configuration is typically done through your domain registrar. Make sure the domain is properly pointed and DNS changes have fully propagated before installing Caddy, to avoid SSL-related errors.

Open Ports 80 (HTTP) and 443 (HTTPS) on the Firewall

These two ports are essential for running a website. Port 80 handles incoming HTTP requests, while port 443 is used for HTTPS traffic. To ensure your website is accessible from the internet, make sure both ports are open in your firewall using the following commands:
  • Open port 80 for HTTP: sudo ufw allow 80/tcp
  • Open port 443 for HTTPS: sudo ufw allow 443/tcp
  • If UFW is not yet enabled: sudo ufw enable
  • Check firewall status: sudo ufw status
Make sure both ports are active to allow Caddy to function smoothly.

How to install Caddy on Ubuntu VPS

Once all the necessary prerequisites are in place, you can proceed to install Caddy on Ubuntu VPS.

Update the System

Before installing Caddy, make sure your VPS has all the latest software packages. This not only improves performance but also addresses potential security issues. Run the following command to update your system:
sudo apt update && sudo apt upgrade -y
Once the update is complete, your server will be in a more stable and secure state, ready for the Caddy installation.
Update the System

Install Required Packages

Next, you need to install a few essential support packages before you install Caddy on Ubuntu VPS. These tools are necessary for managing repositories and downloading the Caddy package:
sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https curl gnupg
These packages must be installed beforehand to ensure that Caddy runs smoothly without encountering critical issues.
In this process:
  • debian-keyring, debian-archive-keyring, and apt-transport-https: Allow your system to securely trust and communicate with HTTPS-based repositories.
  • curl: A command-line tool used to download Caddy’s GPG key.

Add the Official Caddy Repository

After installing the required packages, the next step is to add Caddy’s official repository to your system. This allows you to easily install and update Caddy in the future.
First, add the Caddy GPG key:
curl -1sLf ‘https://dl.cloudsmith.io/public/caddy/stable/gpg.key’ | sudo gpg –dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
Then, add the Caddy repository:
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/s.list.d/caddy-stable.list
These steps ensure that your system is set up to receive the latest stable version of Caddy directly from the official source.

Install Caddy

Finally, you can install Caddy using the following commands:
sudo apt update
sudo apt install caddy -y
Once the installation is complete, Caddy will run as a systemd service and start automatically whenever your VPS reboots.

Verify the Installation

Successfully installed Caddy on Ubuntu VPS
After you install Caddy on Ubuntu VPS, it’s important to verify that the installation was successful by checking the service status.

Check Caddy Version:

To confirm that Caddy is installed and can run properly, check its version: caddy version
You should see output showing the installed version of Caddy, for example: v2.x.x. If you receive a “command not found” error, review the installation steps to ensure everything was completed correctly.
Check Caddy Service Status:
To verify the status of the Caddy service, run the following command: sudo systemctl status caddy
If the output shows active (running), it means that Caddy is running properly.

Configure Your First Website with Caddy

Caddy uses the main configuration file called Caddyfile, usually located at /etc/caddy/Caddyfile.
Simple example:
Assuming you have the domain example.com, update the Caddyfile content as follows:
example.com {
root * /var/www/html
file_server
}
Then create the website directory:
sudo mkdir -p /var/www/html
echo “Hello from Caddy!” | sudo tee /var/www/html/index.html
Reload Caddy to apply the configuration:
sudo systemctl reload caddy
And now, when you access https://example.com, you will see the message “Hello from Caddy!” along with an automatically issued SSL certificate.
Access Caddy Web Server

Comparison of Caddy and Nginx on Ubuntu VPS

The following comparison table will help you clearly understand the differences and see why Caddy is becoming a popular choice for many users.

Criteria Caddy Nginx
Automatic SSL Configuration Yes, free via Let’s Encrypt Manual configuration required (eg, with Certbot)
HTTP/3 Enabled by default Requires manual compilation
Configuration File Very simple (Caddyfile) More complex (nginx.conf)
Setup Speed Faster and easier Takes more time
Performance High. handles concurrency well Very high, optimized for large-scale traffic
Scalability Easy with reverse proxy and load balancing Very flexible, supports many modules
Popularity Rapidly growing Widely used, large community
VPSWindows has just guided you through the process of installing Caddy on an Ubuntu VPS in the most detailed and easy-to-understand way. From learning what Caddy is and why it’s a great choice, to preparing your system, installing each component, and finally configuring a basic website. Setting up Caddy on your Ubuntu VPS not only gives you a high-performance web server but also greatly simplifies SSL/TLS management, helping your website stay secure and SEO-friendly. Visit VPSWindows to explore more useful tech tutorials!
Exit mobile version