DEV Community

NeutronCloud
NeutronCloud

Posted on

How to Install Caddy on Rocky Linux 8

In this article, we'll explain you how to install Caddy on Rocky Linux 8.  Host your website on Caddy web server.

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 Rocky Linux 8 installed cloud instance.
  • A root user access or normal user with administrative privileges.

Install Caddy on Rocky Linux 8

1. Keep the server up to date

# dnf update -y

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

# dnf install 'dnf-command(copr)'

# dnf copr enable @caddy/caddy

# dnf install caddy -y

Next, start and enable caddy.service using following command:

# systemctl start caddy && systemctl enable caddy

Configure Firewall

Assuming that you are using firewalld as your server's firewall, run following command to add the HTTP and HTTPS port in the firewall.

# firewall-cmd --add-port=80/tcp --permanent

# firewall-cmd --add-port=443/tcp --permanent

# firewall-cmd --reload

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

http://Server-IP

OR

http://example.com

Install Caddy on Rocky Linux 8

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 neutroncloud.in with your domain name

Create a directory for your website files

# mkdir /usr/share/neutroncloud.in/

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

# vi /etc/caddy/Caddyfile

Replace :80 with your domain name and change the site root to /usr/share/neutroncloud.in/ as

install caddy webserver

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/neutroncloud.in 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 /usr/share/neutroncloud.in/index.html

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 Rocky Linux 8.

Deploy cloud servers in India

Top comments (0)