Introduction
In this tutorial, we will learn about how to install Caddy web server on Linux using 6 easy steps. Caddy is one of the most demanding web server among the developers due to it’s automatic HTTPS feature that ensures secure web communications. We will look into more detail about Caddy and install the package in CentOS 7 Linux system.
Caddy Overview
Caddy is a modern, open-source web server software that is known for its simplicity, ease of use and built-in automation features. It is designed to make web server configuration and management straightforward while providing robust security and performance. Caddy’s unique selling point is its automatic HTTPS by default, making it an attractive choice for many users.
There are many usage of Caddy. Some of the key usage are listed below.
Automatic HTTPS: Caddy is famous for its built-in Let’s encrypt integration, which automatically secures websites with HTTPS certificates. This feature simplifies the process of securing websites, ensuring data privacy and security.
Web Hosting: Caddy is used by web hosting providers and companies to serve websites and web applications. Its automatic HTTPS and ease of configuration makes it a popular choice.
Static Site Hosting: Caddy’s automatic configuration capabilities makes it a good choice for hosting static websites and blogs.
Secure File Sharing: Caddy’s automatic HTTPS makes it suitable for secure file sharing and collaboration platforms.
Apart from above, Caddy is also used as API Gateways, Personal Web servers, IoT and Edge computing, DevOps& containers etc.
How to Install Caddy Web Server on Linux: [6 Easy Steps]
Also read: How to Install Nginx Web Server on Rocky Linux: [7 Easy Steps]
Prerequisite
- CentOS 7 installed
- Non-root user with sudo privilege/root user access.
- Basic Linux Command understanding
Step-1: Check OS Version
In this step, check the version of your Linux operating system using below command.
[root@linuxnasa ~]# cat /etc/os-release NAME="CentOS Linux" VERSION="7 (Core)" ID="centos" ID_LIKE="rhel fedora" VERSION_ID="7" PRETTY_NAME="CentOS Linux 7 (Core)" ANSI_COLOR="0;31" CPE_NAME="cpe:/o:centos:centos:7" HOME_URL="https://www.centos.org/" BUG_REPORT_URL="https://bugs.centos.org/" CENTOS_MANTISBT_PROJECT="CentOS-7" CENTOS_MANTISBT_PROJECT_VERSION="7" REDHAT_SUPPORT_PRODUCT="centos" REDHAT_SUPPORT_PRODUCT_VERSION="7"
Step-2: Update Repository
In this step update the repository using yum update command which will update all the packages to their latest version. After that execute yum upgrade command which will delete all the obsolete packages from the repository.
[root@linuxnasa ~]# yum -y update && yum -y upgrade
Step-3: Install Corp Plugin
In this step, install the yum-plugin-copr plugin which will allow the yum to work with Copr repositories, making it easier to install and manage packages from these repositories using yum package manager..
[root@linuxnasa ~]# yum install yum-plugin-copr
Next, enable the Copr project/group named @caddy/caddy using yum package manager as shown below.
[root@linuxnasa ~]# yum -y copr enable @caddy/caddy Loaded plugins: copr, fastestmirror You are about to enable a Copr repository. Please note that this repository is not part of the main Fedora 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://fedorahosted.org/copr/wiki/UserDocs#WhatIcanbuildinCopr>, and packages are not held to any quality or securty level. Please do not file bug reports about these packages in Fedora Bugzilla. In case of problems, contact the owner of this repository. copr done
NOTE:
- Caddy package is not available in yum repository. It is available in Copr repository which can be installed using the plugin called ‘yum-plugin-copr‘.
- Copr repositories are often organized into projects or groups. @caddy/caddy is name of the one of the project/group.
Step-4: Install Caddy
In this step, install the Caddy package using below command.
[root@linuxnasa ~]# yum -y install caddy Loaded plugins: copr, fastestmirror Loading mirror speeds from cached hostfile * base: centos.mirror.far.fi * centos-qemu-ev: centos.mirror.far.fi * epel: www.nic.funet.fi * extras: centos.mirror.far.fi * updates: centos.mirror.far.fi copr:copr.fedorainfracloud.org:group_caddy:caddy | 1.8 kB 00:00:00 copr:copr.fedorainfracloud.org:group_caddy:caddy/x86_64/primary | 1.3 kB 00:00:00 copr:copr.fedorainfracloud.org:group_caddy:caddy 3/3 Resolving Dependencies There are unfinished transactions remaining. You might consider running yum-complete-transaction, or "yum-complete-transaction --cleanup-only" and "yum history redo last", first to finish them. If those don't work you'll have to try removing/installing packages by hand (maybe package-cleanup can help). --> Running transaction check ---> Package caddy.x86_64 0:2.7.4-1.el7 will be installed --> Finished Dependency Resolution Dependencies Resolved ================================================================================================================================== Package Arch Version Repository Size ================================================================================================================================== Installing: caddy x86_64 2.7.4-1.el7 copr:copr.fedorainfracloud.org:group_caddy:caddy 24 M Transaction Summary ================================================================================================================================== Install 1 Package Total download size: 24 M Installed size: 60 M Downloading packages: warning: /var/cache/yum/x86_64/7/copr:copr.fedorainfracloud.org:group_caddy:caddy/packages/caddy-2.7.4-1.el7.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID d605147e: NOKEY Public key for caddy-2.7.4-1.el7.x86_64.rpm is not installed caddy-2.7.4-1.el7.x86_64.rpm | 24 MB 00:00:00 Retrieving key from https://download.copr.fedorainfracloud.org/results/@caddy/caddy/pubkey.gpg Importing GPG key 0xD605147E: Userid : "@caddy_caddy (None) <@caddy#[email protected]>" Fingerprint: 4a76 f92f f6d4 0440 f8fc 4f36 c521 91b1 d605 147e From : https://download.copr.fedorainfracloud.org/results/@caddy/caddy/pubkey.gpg Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : caddy-2.7.4-1.el7.x86_64 1/1 Verifying : caddy-2.7.4-1.el7.x86_64 1/1 Installed: caddy.x86_64 0:2.7.4-1.el7 Complete!
Step-5: Enable Caddy Service
In this step, start and enable the caddy service to make is system wide accessible using below commands in order.
//To start caddy service [root@linuxnasa ~]# systemctl start caddy //To enable caddy service [root@linuxnasa ~]# systemctl enable caddy Created symlink from /etc/systemd/system/multi-user.target.wants/caddy.service to /usr/lib/systemd/system/caddy.service.
Next, check the status of caddy service. It must be in active state.
[root@linuxnasa ~]# systemctl status caddy ● caddy.service - Caddy Loaded: loaded (/usr/lib/systemd/system/caddy.service; enabled; vendor preset: disabled) Active: active (running) since Sat 2023-09-16 19:21:28 IST; 49s ago Docs: https://caddyserver.com/docs/ Main PID: 1990193 (caddy) CGroup: /system.slice/caddy.service └─1990193 /usr/bin/caddy run --environ --config /etc/caddy/Caddyfile Sep 16 19:21:28 linuxnasa systemd[1]: Started Caddy. Sep 16 19:21:28 linuxnasa caddy[1990193]: {"level":"info","ts":1694872288.1234426,"msg":"using provided configuration"...r":""} Sep 16 19:21:28 linuxnasa caddy[1990193]: {"level":"info","ts":1694872288.1280417,"logger":"admin","msg":"admin endpoi...019"]} Sep 16 19:21:28 linuxnasa caddy[1990193]: {"level":"warn","ts":1694872288.128301,"logger":"http.auto_https","msg":"ser...t":80} Sep 16 19:21:28 linuxnasa caddy[1990193]: {"level":"info","ts":1694872288.1286058,"logger":"http.log","msg":"server ru..."h3"]} Sep 16 19:21:28 linuxnasa caddy[1990193]: {"level":"info","ts":1694872288.1290278,"msg":"autosaved config (load with -...json"} Sep 16 19:21:28 linuxnasa caddy[1990193]: {"level":"info","ts":1694872288.1290927,"msg":"serving initial configuration"} Sep 16 19:21:28 linuxnasa caddy[1990193]: {"level":"info","ts":1694872288.1293564,"logger":"tls.cache.maintenance","ms...ee80"} Sep 16 19:21:28 linuxnasa caddy[1990193]: {"level":"info","ts":1694872288.1293979,"logger":"tls","msg":"cleaning stora...addy"} Sep 16 19:21:28 linuxnasa caddy[1990193]: {"level":"info","ts":1694872288.1294327,"logger":"tls","msg":"finished clean...nits"} Hint: Some lines were ellipsized, use -l to show in full.
Step-6: Verify Caddy Access in System
In this step, open your browser and type ‘localhost‘ or eth0 IP address in the url. If you see the default Caddy home page as shown below, that means it has been installed and configured successfully in your system.
Summary
We have successfully installed Caddy in CentOS 7 system. Similarly, Caddy can be installed on other Linux distributions and on other operating systems (Windows, MacOS). You can follow the Caddy official documentation caddyserver.com to install on any operating system.