Install & Configure the Caddy web server on a CentOS 7 VPS

Caddy is an open source web server that is quite popular with the developer community. Caddy is secure by default! Yes you heard that right, it uses HTTPS by default thus it preserves your privacy as well as prevents man in the middle (MITM) attacks.

In this how-to article, we shall show you how to install Caddy web server on CentOS 7 VPS.

Overview

With Caddy’s excellent features described below,am sure you want to switch your web server.

  • Caddy’s easy to use interface- whether you are a seasoned professional or a fresh beginner, Caddy always has something for you.
  • Command line interface – Caddy can efficiently run from its own CLI. It’s cross-platform hence no worries when using different systems. The commands can be configured to run on startup or shutdown.
  • Plugins- if you want more control over Caddy, you can download as many plugins as you wish. The good thing is that Caddy plugins are easier to write.
  • Logs – Caddy stores its log files systematically hence helping you whenever you want to troubleshoot errors. If your log files become big, Caddy will automatically rotate them so that it can conserve space.
  • Custom builds- with Caddy when downloading, you can choose which plugins you want, and your custom build will be made for you in just a few seconds.
  • Speed- did I mention that Caddy is fast? Yes, it is, with its technology, it makes use of idle CPU cores whenever more power is needed.

Prerequisites

  • A VPS server running latest version of CentOS;CentOS 7.
  • An SSH client to connect to the VPS.

How to Install & Configure the Caddy web server on a CentOS 7 VPS

Update packages in CentOS 7

We have to make sure that we update all available packages on our server. Therefore, type the following command.

$ sudo yum clean all
$ sudo yum -y update

Install Caddy

Next, we are going to install Caddy server using the following command;

$ sudo curl https://getcaddy.com | bash -s personal

That installs the Caddy server. To verify the installation type the following.

$ which caddy

Create user

Now the next step includes us creating a user named Caddy. So in your shell, type the following;

$ sudo adduser -r -d /var/www -s /sbin/nologin caddy

Next, since Caddy needs a new directory for hosting Caddy files, let’s create one. So type the following;

$ sudo mkdir /etc/caddy

Now to change the user to the root user, type;

$ sudo chown -R root:caddy /etc/caddy

Install Caddy as a service

Next, we have to install Caddy as a System Service. Therefore type the following command.

$ sudo  curl -s https://raw.githubusercontent.com/mholt/caddy/master/dist/init/linux-
systemd/caddy.service -o /etc/systemd/system/caddy.service

Then open the Caddy service file

$ sudo vi /etc/systemd/system/caddy.service;

and make the following changes.

User=caddy
Group=caddy

Now save the file and exit vim then restart Caddy service to enable the changes.

$ sudo systemctl daemon-reload
$ sudo systemctl enable caddy.service
$ sudo systemctl status caddy.service

Test Caddy web server

Our next step will be to make a small test web page for Caddy. The test web page is to help us confirm the installation. So go ahead and create the following.

# /var/www/index.html
<h1>Hello World!</h1>

Next up, open the Caddy file and add the following code to it.

$ sudo  vi /etc/caddy/Caddyfile


http:// {
root /var/www
gzip
}

The above code will help Caddy to bind the HTTP port 80.

Start and enable the Caddy service.

$ sudo systemctl start caddy
$ sudo systemctl enable caddy

Then add both HTTP and HTTPS service to the server firewall.

$ firewall-cmd -- permanent -- zone=public -- add-service=http
$ firewall-cmd -- permanent -- zone=public -- add-service=https
$ firewall-cmd -reload

Conclusion

You now have the world’s first secure server at your disposal. If CentOS is your operating system get started with using Caddy web server. Enjoy Caddy’s excellent and secure technology.

 

Check out these top 3 VPS services:

HostArmada
$2.49 /mo
Starting price
Visit HostArmada
Rating based on expert review
  • User Friendly
    4.5
  • Support
    4.5
  • Features
    4.5
  • Reliability
    4.5
  • Pricing
    4.0
A2 Hosting
$2.99 /mo
Starting price
Visit A2 Hosting
Rating based on expert review
  • User Friendly
    4.5
  • Support
    4.0
  • Features
    4.5
  • Reliability
    4.8
  • Pricing
    4.0
Hostens
$0.90 /mo
Starting price
Visit Hostens
Rating based on expert review
  • User Friendly
    4.5
  • Support
    3.8
  • Features
    4.3
  • Reliability
    4.5
  • Pricing
    4.8

How to Install & Configure the Caddy web server on an Ubuntu 18.04 VPS

Caddy is the only new server's that secure by default. It's growing in popularit
3 min read
Eliran Ouzan
Eliran Ouzan
Web Designer & Hosting Expert

How to Enable Apache Mod_Rewrite on an Ubuntu 18.04 VPS or Dedicated Server

In this tutorial, we will cover the basics of enabling mod_rewrite on an Ubuntu
3 min read
Max Ostryzhko
Max Ostryzhko
Senior Web Developer, HostAdvice CTO

How to Install and Configure Linux Malware Detect on CentOS 7

This tutorial will help you install and configure Linux Malware Detect (LMD) on
4 min read
Eliran Ouzan
Eliran Ouzan
Web Designer & Hosting Expert

How to Configure Nginx and Apache on the same Ubuntu VPS or Dedicated Server

Nginx and Apache are great and powerful web servers. However, they both have dra
2 min read
Idan Cohen
Idan Cohen
Marketing Expert
HostAdvice.com provides professional web hosting reviews fully independent of any other entity. Our reviews are unbiased, honest, and apply the same evaluation standards to all those reviewed. While monetary compensation is received from a few of the companies listed on this site, compensation of services and products have no influence on the direction or conclusions of our reviews. Nor does the compensation influence our rankings for certain host companies. This compensation covers account purchasing costs, testing costs and royalties paid to reviewers.