How To Install Caddy Web Server on CentOS 7

Caddy Web Server on CentOS 7

KDE is a well-known desktop environment for the Unix-Like systems designed for users who wants to have a nice desktop environment for their machines, It is one of the most used desktop interfaces out there.

Table of Contents

Step 1. First let’s start by ensuring your system is up-to-date.

Step 2. Installing Caddy web server on CentOS 7.

Step 3. Setting Up Necessary Directories.

Step 4. Installing Caddy as a System Service.

Step 5. Creating Test Web Page and a Caddyfile.

Prerequisites

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo’ to the commands to get root privileges. I will show you through the step by step installation KDE Plasma desktop environment on a CentOS 7 server.
Caddy Features

Automatic HTTPS.
Easy Deployment.
Multi-core.
WebSockets.
Rewrites & Redirects.
Virtual Hosts.

Install Caddy Web Server on CentOS 7

Step 1. First let’s start by ensuring your system is up-to-date.

yum clean all
yum -y update

Step 2. Installing Caddy web server on CentOS 7.

Install Caddy is quick and easy with run the following command:

curl https://getcaddy.com | bash

After the script finishes, you can run the following command to see where is your Caddy’s binary file:

which caddy

Your output should be like below:

/usr/local/bin/caddy

Step 3. Setting Up Necessary Directories.

Next, create the directories where we will store the Caddy configuration file Caddyfile and SSL certificates:

mkdir /etc/caddy
chown -R root:caddy /etc/caddy
touch /etc/caddy/Caddyfile
mkdir /etc/ssl/caddy
chown -R caddy:root /etc/ssl/caddy
chmod 0770 /etc/ssl/caddy
mkdir /var/www
chown caddy:caddy /var/www

Step 4. Installing Caddy as a System Service.

We also need to create a new SystemD configuration script:

cd /etc/systemd/system/
nano caddy.service

Add following line:

[Unit]
Description=Caddy HTTP/2 web server
Documentation=https://caddyserver.com/docs
After=network-online.target
Wants=network-online.target systemd-networkd-wait-online.service

[Service]
Restart=on-failure
StartLimitInterval=86400
StartLimitBurst=5

; User and group the process will run as.
User=caddy
Group=caddy

; Letsencrypt-issued certificates will be written to this directory.
Environment=CADDYPATH=/etc/ssl/caddy

; 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

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

; Use private /tmp and /var/tmp, which are discarded after caddy stops.
PrivateTmp=true
; Use a minimal /dev
PrivateDevices=true
; Hide /home, /root, and /run/user. Nobody will steal your SSH-keys.
ProtectHome=true
; Make /usr, /boot, /etc and possibly some more folders read-only.
ProtectSystem=full
; … 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!
ReadWriteDirectories=/etc/ssl/caddy

; 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.
;CapabilityBoundingSet=CAP_NET_BIND_SERVICE
;AmbientCapabilities=CAP_NET_BIND_SERVICE
;NoNewPrivileges=true

[Install]
WantedBy=multi-user.target

Set the owner and permissions:

chown root:root /etc/systemd/system/caddy.service
chmod 644 /etc/systemd/system/caddy.service

At last, execute the following commands to enable Caddy to run on boot:

systemctl enable caddy
systemctl start caddy

Step 5. Creating Test Web Page and a Caddyfile.

For testing purposes, we will create a test HTML file:

mkdir -p /var/www/wpcademy.com
echo "Caddy" > /var/www/wpcademy.com/index.html
chown -R www-data: /var/www/my-domain.com

Next, add our domain to the Caddy configuration file:

nano /etc/caddy/Caddyfile

Add following line:

my-domain.com {
    root /var/www/wpcademy.com
}

Save the file and exit the editor. To apply the changes, restart Caddy:

systemctl restart caddy.service

Now, with a web browser, just go to https://wpcademy.com, and you will see our test page!

Congratulation’s! You have successfully installed Caddy. Thanks for using this tutorial for installing Caddy web server in CentOS 7 system. For additional help or useful information, we recommend you to check the official Caddy web server web site.

 

How To Install Caddy Web Server on Ubuntu 16.04 LTS

Install Caddy Web Server on Ubuntu 16

Caddy is a modern, general-purpose, multi-platform web server which supports Virtual hosting, HTTP/2, IPv6, Markdown, WebSockets, FastCGI, automatic HTTPS via Let’s Encrypt, templates and more.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo’ to the commands to get root privileges. I will show you through the step by step installation Caddy Web Server on a Ubuntu 16.04 Xenial Xerus server.

Install Caddy Web Server on Ubuntu 16.04 LTS

Step 1. First make sure that all your system packages are up-to-date by running these following apt-get commands in the terminal.

sudo apt-get update
sudo apt-get upgrade

Step 2. Installing Caddy Web Server.

Install Caddy is quick and easy with run the following command:

curl https://getcaddy.com | bash

Once the installation is completed, we need to add the cap_net_bind_servicecapability to the Caddy binary:

sudo setcap cap_net_bind_service=+ep /usr/local/bin/caddy

Step 3. Setting Up Necessary Directories.

Next, create the directories where we will store the Caddy configuration file Caddyfile and SSL certificates:

sudo mkdir /etc/caddy
sudo chown -R root:www-data /etc/caddy
sudo mkdir /etc/ssl/caddy
sudo chown -R www-data:root /etc/ssl/caddy
sudo chmod 0770 /etc/ssl/caddy
sudo touch /etc/caddy/Caddyfile
sudo mkdir /var/www
sudo chown www-data: /var/www

Step 4. Installing Caddy as a System Service.

We also need to create a new SystemD configuration script:

nano /lib/systemd/system/caddy.service

Add following line:

[Unit]
Description=Caddy HTTP/2 web server
Documentation=https://caddyserver.com/docs
After=network-online.target
Wants=network-online.target

[Service]
Restart=on-failure
StartLimitInterval=86400
StartLimitBurst=5

User=www-data
Group=www-data
; Letsencrypt-issued certificates will be written to this directory.
Environment=CADDYPATH=/etc/ssl/caddy

ExecStart=/usr/local/bin/caddy -log stdout -agree=true -conf=/etc/caddy/Caddyfile -root=/var/tmp
ExecReload=/bin/kill -USR1 $MAINPID

LimitNOFILE=1048576
LimitNPROC=64

PrivateTmp=true
PrivateDevices=true
ProtectHome=true
ProtectSystem=full
ReadWriteDirectories=/etc/ssl/caddy

; 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.
;CapabilityBoundingSet=CAP_NET_BIND_SERVICE
;AmbientCapabilities=CAP_NET_BIND_SERVICE
;NoNewPrivileges=true
[Install]
WantedBy=multi-user.target

Execute the following commands to enable Caddy to run on boot:

systemctl enable caddy.service
systemctl restart caddy.service

Step 5. Creating Test Web Page and a Caddyfile.

For testing purposes, we will create a test HTML file:

mkdir -p /var/www/wpcademy.com
echo "Caddy" > /var/www/wpcademy.com/index.html
chown -R www-data: /var/www/my-domain.com

Next, add our domain to the Caddy configuration file:

nano /etc/caddy/Caddyfile

Add following line:

my-domain.com {
    root /var/www/wpcademy.com
}

Save the file and exit the editor. To apply the changes, restart Caddy:

systemctl restart caddy.service

Now, with a web browser, just go to https://wpcademy.com, and you will see our test page!

Congratulation’s! You have successfully installed Caddy. Thanks for using this tutorial for installing Caddy web server in Ubuntu 16.04 Xenial Xerus system. For additional help or useful information, we recommend you to check the official Caddy web server web site.