How to Install Caddy Web Server On AlmaLinux 9

Caddy is a powerful, enterprise-ready, open-source web server with automatic HTTPS written in Go. It is known for its simplicity, ease of use, and high performance. Caddy is designed to be secure by default, providing robust features such as automatic TLS certificate management and HTTP/2 support.

Update the system packages

Before installing any new software, it's important to make sure your system packages are up to date.

dnf update

Ensures all existing packages are up to date.

Install the DNF plugin for COPR

To enable the Caddy repository, you need to install the DNF plugin for COPR.

dnf install 'dnf-command(copr)'

Output:

[root@vps ~]# sudo dnf install 'dnf-command(copr)'
Last metadata expiration check: 0:07:29 ago on Saturday 06 July 2024 09:40:09 AM UTC.
Package dnf-plugins-core-4.0.21-25.el8.noarch is already installed.
Dependencies resolved.
Nothing to do.
Complete!

The dnf-command(copr) plugin is needed to enable the COPR repository for Caddy.

Enable the Caddy repository

This step allows you to access the Caddy package from a third-party repository.

dnf copr enable @caddy/caddy

Output:

[root@vps ~]# sudo dnf copr enable @caddy/caddy
Enabling a Copr repository. Please note that this repository is not part
of the main distribution, and quality may vary.

The Fedora Project does not exercise any power over the contents of
this repository beyond the rules outlined in the Copr FAQ at
<https://docs.pagure.org/copr.copr/user_documentation.html#what-i-can-build-in-copr>,
and packages are not held to any quality or security level.

Please do not file bug reports about these packages in Fedora
Bugzilla. In case of problems, contact the owner of this repository.

Do you really want to enable copr.fedorainfracloud.org/@caddy/caddy? [y/N]: y
Repository successfully enabled.
[root@vps ~]#

Enables the COPR repository for Caddy to download the Caddy package.

Install Caddy

With the repository enabled, you can now install the Caddy package.

dnf install caddy -y

Output:

[root@vps ~]# sudo dnf install caddy -y
Copr repo for caddy owned by @caddy                                                                               536  B/s | 1.7 kB     00:03    
Dependencies resolved.
==================================================================================================================================================
 Package               Architecture           Version                      Repository                                                        Size
==================================================================================================================================================
Installing:
 caddy                 x86_64                 2.8.4-1.el8                  copr:copr.fedorainfracloud.org:group_caddy:caddy                  12 M

Transaction Summary
==================================================================================================================================================
Install  1 Package

Installs Caddy from the enabled COPR repository.

Start and enable Caddy service

After installation, it's important to start the Caddy service and enable it to start on boot.

systemctl start caddy && sudo systemctl enable caddy

Output:

[root@vps ~]# sudo systemctl start caddy && sudo systemctl enable caddy
Created symlink /etc/systemd/system/multi-user.target.wants/caddy.service → /usr/lib/systemd/system/caddy.service.

Starts the Caddy service immediately and enables it to start on boot.

Configure Firewall

Open HTTP and HTTPS ports in the firewall

For Caddy to serve web content, you need to open the HTTP and HTTPS ports in the firewall.

firewall-cmd --add-port={80,443}/tcp --permanent

Output:

[root@vps ~]# sudo firewall-cmd --add-port={80,443}/tcp --permanent
success

Adds rules to the firewall to allow traffic on ports 80 (HTTP) and 443 (HTTPS).

Reload the firewall to apply changes

After adding new firewall rules, you need to reload the firewall to apply them.

firewall-cmd --reload

Output:

[root@vps ~]# sudo firewall-cmd --reload
success

Verify the Caddy installation,

caddy -v

Output:

[root@vps ~]# caddy -v
v2.8.4 h1:q3pe0wpBj1OcHFZ3n/1nl4V4bxBrYoSoab7rL9BMYNk=
[root@vps ~]#

Navigate Caddy Web Server

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

http://Server-IP
or
http://Your_Domain.com

Note: Replace Your_Domain with actual domain name

images

That's it! You have successfully installed and configured Caddy on AlmaLinux 9 using the package manager.