How to Install Caddy Web Server on CentOS 8

Install Caddy Web Server on CentOS 8

In this article, we will have explained the necessary steps to installing and configure the Caddy web server on CentOS 8. Before continuing with this tutorial, make sure you are logged in as a user with sudo privileges. All the commands in this tutorial should be run as a non-root user.

Caddy is a powerful, enterprise-ready, open-source web server with automatic HTTPS written in Go. Caddy includes modern features such as support for virtual hosts, minification of static files, and HTTP/2. Caddy is also the first web server that can obtain and renew SSL/TLS certificates automatically using Let’s Encrypt. Caddy support all popular platforms that are why it is available for Windows, macOS, Linux, BSD, Android, Solaris, 32-bit, x64, ARM, mips64, and more

Install Caddy Web Server on CentOS 8

Step 1. The first command will update the package lists to ensure you get the latest version and dependencies.

sudo dnf install epel-release
sudo dnf update

Step 2. Install Caddy Web Server on CentOS 8 system.

Now install Candy using the following command:

sudo dnf install 'dnf-command(copr)'
sudo dnf copr enable @caddy/caddy
sudo dnf install caddy

Step 3. Configuring Firewall.

Allow HTTP and HTTPS ports:

sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo systemctl reload firewalld

In case your firewall is not running then simply type:

sudo systemctl enable firewall-cmd
sudo systemctl start firewall-cmd

Step 4. Create a Demo web page to test the Caddy web server.

Set up a document root for your website. A document root is a directory where your website files are stored:

sudo mkdir -p /var/www/your-domain.com/html
sudo mkdir /var/log/caddy

Set the ownership of the directory to Caddy:

sudo chown caddy:caddy /var/www/your-domain.com/html -R
sudo chown caddy:caddy /var/log/caddy

Next, create an HTML file to test:

sudo nano /var/www/your-domain.com/html/index.html

Add the following line:

<!DOCTYPE html>
<html>
<head>
<title>Hello from Caddy!</title>
</head>
<body>
<h1>Hello, from Caddy!</h1>
</body>
</html>

Then, restart Caddy to enable the configuration:

sudo systemctl restart caddy

Step 5. Accessing Caddy Web Server.

After successfully configured, now open in your browser, and you should see the following page which means, the configuration is working.

http://your-domain.com

That’s all you need to do to install Caddy on CentOS 8. I hope you find this quick tip helpful. For further reading on the Caddy web server, please refer to their official knowledge base. If you have questions or suggestions, feel free to leave a comment below.