What is Caddy? Well Caddy is: The Ultimate Webserver! or at least that is what they say!

Honestly your best bet is to just read up on them, as they are awesome and I have personally used them for several different projects in different areas of projects as well. https://caddyserver.com/features

Caddy is a very powerful webserver that can be configured for many things from a static site, download site, php/mysql driven site, proxy, and more. So lets get started and setup a few demos.

Caddy can be configured to run on many different OS’s Caddy Documents For we are going to us Debian/Ubuntu as I personally now run both of those OS’s. I am going to focus on Ubuntu. So head over to your favorite VPS provider and spin up a VPS. As specs for this a crazy low, but lets not push it to save $1/2.

Lets login to your newly created VPS. Now once in lets start to build the server.

## Update the VPS.
apt-get update && apt-get upgrade


## Lets install the firewall and open the only three ports you will need.

apt install ufw
ufw allow 22
ufw allow 80
ufw allow 443
ufw enable

## Install Caddy

apt install -y debian-keyring debian-archive-keyring apt-transport-https curl -y
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-stable.list
apt-get update
apt-get install caddy -y

## Install PHP and MySQL
apt-get install php-fpm php-mysql php-curl php-gd php-mbstring php-common php-xml php-xmlrpc mariadb-server mariadb-client -y

## Now lets edit a conf file to allow Caddy to run as instead of www-data
nano /etc/php/7.4/fpm/pool.d/www.conf

## Locate and Change the following
user = caddy
group = caddy
listen.owner = caddy
listen.group = caddy

## Save the file and exit
## Restart PHP
systemctl restart php7.4-fpm

## That is it, your full Webserver Stack is now setup and ready to go

## Now lets added our three demo sites to the configuration.
## Site One: static.theserveradmin.com - Demo of static content.  HTML, Images, Downloads
## WordPress Install: wordpress.theserveradmin.com - Demo of a default WordPress Install.
## Cache'd WordPress: cache.theserveradmin.com - Same demo but with caching enabled.

## Edit the Caddy File.
nano /etc/caddy/Caddyfile

## Added the following ** Change to your needs.
static.theserveradmin.com:443 {
        root * /home/static.theserveradmin.com
        encode gzip zstd
        file_server
}

wordpress.theserveradmin.com:443 {
        root * /home/wordpress.theserveradmin.com
        encode gzip zstd
        php_fastcgi unix//run/php/php7.4-fpm.sock
}

cache.theserveradmin.com:443 {
        root * /home/cache.theserveradmin.com
        encode gzip zstd
        php_fastcgi unix//run/php/php7.4-fpm.sock		
}

## Save and Exit

That is it!!  Now just restart the Caddy Server and it will connect, and start to issue the SSL's for you.
But wait!!!  You made the correct directories didn't you?  :-)

## Restart Caddy
systemctl restart caddy

By Anthony

Leave a Reply

Your email address will not be published. Required fields are marked *