Caddy is an HTTP web server, under an open-source license, written in GO language. Here we will learn how to install Caddy Server on RHEL based AlmaLinux or Rocky Linux 8 using the command line (terminal) on VPS, cloud, or local machines.
Although Caddy is not popular as Apache or Nginx, yet a powerful web server that is ready to cater to enterprises’ needs. It is modular and can be used for static file serving, reverse proxying, Kubernetes ingress, and more… Further, Caddy can fetch and renew TLS certificates for the website you are running automatically.
Here are a few of its offerings, caddy supports HTTP/1.1, HTTP/2, and experimental HTTP/3, scalability, HTTPS support by the box; Dynamic configuration, low memory consumption, No Dependencies; Modular Stack, Caddy’s REST API makes it easy to automate; due to Go language – Caddy is a cross-platform web server that can run on Windows, macOS, Linux, BSD, Android, Solaris, 32-bit, amd64, ARM, aarch64, mips64… Its features can be extended with plugins.
Steps to install Caddy in Almalinux or Rocky Linux 8 server
The given steps and commands will also work for other Linux operating systems based on RHEL or RPM such as CentOS/RedHat 8/Oracle Linux…
What do you require to perform this guide?
A user with sudo
access
Almalinux or Rocky
Of course, Internet connection.
1. Run DNF Update
If you are using a fresh server or haven’t updated your server for a while, then first run the system update command. This will rebuild the DNF repository cache.
sudo dnf update
2. Install Copr repository to Almalinux or Rocky 8
Unlike Apache or Nginx, the packages we needed to install the Caddy web server are not available via the default base repository of either Almalinux 8 or Rocky Linux. Hence, we have to add Fedora maintained repository called Copr. It hosts more than 17,000 projects and is meant to provide the installation packages of such projects to Fedora and other RPM Linux users automatically whenever users call for the same. However, before that, we have to manually add it to our system using the given command.
sudo dnf install 'dnf-command(copr)'
3. Enable Caddy server repo
Now, enable which package repo you want to enable, here it is Caddy.
sudo dnf copr enable @caddy/caddy
Once again run the system update
sudo dnf update
4. Command to install Caddy on Rocky or AlmaLinux 8
Finally, we can use the DNF package manager to install the Caddy web server just like HTTPd or any other application from the command terminal.
sudo dnf install caddy
5. Start and Enable Caddy Service
Once the installation is completed, perhaps the caddy server’s service wouldn’t be running on your system by default. Therefore, start and enable it manually. And to confirm use the status command:
To Start:
sudo systemctl start caddy
To enable, so that it can start automatically:
sudo systemctl enable caddy
Check Status:
systemctl status caddy
6. Open ports 80 and 443 in the firewall
If you are using the Almalinux, Rocky or any other RHEL based system’s in-built firewall then use the given command to open 80/443 ports. However, those who are on Cloud such as Google, AWS, etc. they need to allow public access to these ports or HTTP/HTTPS in their service provider’s firewall.
For port 80 or HTTP
sudo firewall-cmd --permanent --add-service=http
For port 443 or HTTPS:
sudo firewall-cmd --permanent --add-service=https
Reload the system firewall:
sudo systemctl reload firewalld
7. Access Web server Demo page
To confirm the server is up and running to serve our web pages without throwing any error, let’s access it using the web browser. On your system, open the browser and enter that ip-address
or domain name of the server where you are running Caddy.
Example:
http://server-ip
or
http://example.com
Note: server-ip
needs to be replaced with the actual address of your server that can be found using the command ip a
In the same way, if you have forwarded some domain to your server then you can access the Caddy using that as well.
To edit the Caddy host configuration file:
sudo nano /etc/caddy/Caddyfile
You can change the root path to server the web pages you want.
Learn more about it at – https://caddyserver.com/docs/caddyfile
Other Articles:
• How to install MariaDB 10 on AlmaLinux 8 or Rocky Linux
• How to Install WordPress on AlmaLinux 8 | Rocky Linux 8
• Install Gnome GUI on Almalinux or Rocky Linux 8