How to Install Caddy on CentOS 7

r00t November 21, 2017

Install Caddy on CentOS 7

In this tutorial we’ll learn how to install Caddy on CentOS 7. We will also install and configure its prerequisites. Caddy is an open source HTTP Web server Which Employed for various platforms Such as Windows, Mac, Linux, FreeBSD, OpenBSD, etc.. It is a full Featured HTTP/2 web server which may be automatically enables that the HTTPS. It allows the designers to do amazing things with high flexibility And low overhead

I recommend to use a minimal CentOS server setup as a basis for the tutorial, that can be a virtual or a root server image with an CentOS 7 minimal install from a web hosting company or you use our minimal server tutorial to install a server from scratch.

Install Caddy on CentOS 7

Step 1. First, ensure your system is fully up-to-date by running the following:

yum -y update

Step 2. Installing Caddy.

Run the following script, it will download Caddy binary:

curl | bash

After the script finishes, the Caddy binaries are installed on the server and ready to use. You can verify that Caddy binaries have been put in place by using which to check their location:

which caddy

Your output should be like below:


Step 3. Configure Caddy.

Create the home directory /var/www for the Caddy web server, and the house directory /var/www/example. Com for your website:

sudo mkdir -p /var/www/
sudo chown -R caddy:caddy /var/www

Create a directory to store SSL certificates:

sudo mkdir /etc/ssl/caddy
sudo chown -R caddy:root /etc/ssl/caddy
sudo chmod 0770 /etc/ssl/caddy

Create a dedicated directory to store the Caddy config document Caddyfile:

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

Create the Caddy config file named Caddyfile:

sudo touch /etc/caddy/Caddyfile
sudo chown caddy:caddy /etc/caddy/Caddyfile
sudo chmod 444 /etc/caddy/Caddyfile
cat <<EOF | sudo tee -a /etc/caddy/Caddyfile {
 root /var/www/

While Caddy does not install itself as a service, the project provides an official systemd unit file. This file does assume the directory structure we set up in the previous step, so make sure your configuration matches:

nano /etc/systemd/system/caddy.service

Paste the following configuration then save and exit:

Description=Caddy HTTP/2 web server
Documentation= systemd-networkd-wait-online.service


; User and group the process will run as.

; Letsencrypt-issued certificates will be written to this directory.

; Always set "-root" to something safe in case it gets forgotten in the Caddyfile.
ExecStart=/usr/local/bin/caddy -log stdout -agree=true -conf=/etc/caddy/Caddyfile -root=/var/tmp
ExecReload=/bin/kill -USR1 $MAINPID

; Use graceful shutdown with a reasonable timeout

; Limit the number of file descriptors; see `man systemd.exec` for more limit settings.
; Unmodified caddy is not expected to use more than that.

; Use private /tmp and /var/tmp, which are discarded after caddy stops.
; Use a minimal /dev
; Hide /home, /root, and /run/user. Nobody will steal your SSH-keys.
; Make /usr, /boot, /etc and possibly some more folders read-only.
; … except /etc/ssl/caddy, because we want Letsencrypt-certificates there.
; This merely retains r/w access rights, it does not add any new. Must still be writable on the host!

; The following additional security directives only work with systemd v229 or later.
; They further retrict privileges that can be gained by caddy. Uncomment if you like.
; Note that you may have to add capabilities required by any plugins in use.


Start the Caddy service and make it automatically start on system boot:

sudo systemctl daemon-reload
sudo systemctl start caddy.service
sudo systemctl enable caddy.service

Step 4. Create simple test configuration of Caddy.

Use the following command to create a file named index.html in your Caddy site home directory:

echo '<h1>Hello World!</h1>' | sudo tee /var/www/

Restart the Caddy service to load new contents:

sudo systemctl restart caddy.service

Finally, point your web browser to or You should see the message Hello World! as expected.

Congratulation’s! You have successfully install and configured Caddy on your CentOS 7 server. Thanks for using this tutorial for installing Caddy web server on CentOS 7 system.

The Tags:

Leave a Comment

Comments are closed.