install caddy on ubuntu

How to install Caddy on Ubuntu 16.04

Spread the love

In this tutorial, we will show you how to install Caddy on a Ubuntu 16.04 VPS. 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 guide should work on other Linux VPS systems as well but was tested and written for an Ubuntu 16.04 VPS.

Log in to your VPS via SSH

ssh [email protected]_IP

Update the system and install all necessary packages

sudo apt-get update && apt-get -y upgrade
sudo apt-get install curl

Install Caddy

Installing Caddy is quick and easy:

curl | bash

If you want to install Caddy with some extra features, you can use the -s switch with a comma-separated list of directives, like in the following example:

curl | bash -s realip,expires,upload

Once the installation is completed, we need to add the cap_net_bind_servicecapability to the Caddy binary. This capability will allow the Caddy executable to bind to a port less than 1024.

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

Next, create the directories where we will store the Caddy configuration file Caddyfile and SSL certificates. The term “Caddyfile” is a plaintext configuration file used to configure how Caddy works. This configuration file is very similar in purpose to httpd.conf in Apache or nginx.conf in Nginx.

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

SystemD Configuration

We also need to create a new SystemD configuration script:

sudo nano /lib/systemd/system/caddy.service
Description=Caddy HTTP/2 web server


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

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



; 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.

Enable Caddy to start on boot:

sudo systemctl enable caddy.service

Testing Caddy

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

sudo mkdir -p /var/www/
sudo echo "Caddy" > /var/www/
sudo chown -R www-data: /var/www/

and add our domain to the Caddy configuration file.

sudo nano /etc/caddy/Caddyfile {
    root /var/www/

Start Caddy with the following command:

sudo systemctl start caddy.service

You can now access your domain at

For more information about how to manage your Caddy web server, please refer to the Caddy documentation.

Of course, you don’t have to do any of this if you use one of our Server Setup and Optimization Services, in which case you can simply ask our expert Linux admins to install Caddy on your server for you. They are available 24×7 and will take care of your request immediately.

PS. If you liked this post, please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.

Leave a Reply

Your email address will not be published.