Caddy Server 2 + PHP-FPM Installation on Linux

Start with downloading Caddy 2 Linux binary.

https://github.com/caddyserver/caddy/releases/download/v2.0.0-beta.17/caddy2_beta17_linux_amd64

Rename it as caddy.

mv caddy2* caddy

Move file to /usr/bin

mv caddy /usr/bin/

Add a group called caddy

groupadd --system caddy

Add a user to the group

useradd --system \
	--gid caddy \
	--create-home \
	--home-dir /var/lib/caddy \
	--shell /usr/sbin/nologin \
	--comment "Caddy web server" \
	caddy

Go to /etc/systemd/system/ and download caddy.service file.

cd etc/systemd/system
wget https://raw.githubusercontent.com/caddyserver/dist/master/init/caddy.service

Go to /etc and create a caddy directory.

cd etc
mkdir caddy

Create a Caddyfile in /etc/caddy folder with sample content below.

example.com {
root * /var/www/html/
try_files {path} {path}/ /index.php?{query}
php_fastcgi unix//run/php/php7.3-fpm.sock
file_server
}

Install PHP-FPM

apt install php-fpm

Start and enable PHP-FPM as a service.

systemctl enable php7.3-fpm
systemctl start php7.3-fpm

Start Caddy as a service.

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

Note that, If you’re using Ubuntu 18.04 then your php-fpm version is 7.2