Using the Caddy web server with Laravel is quite easy and straightforward (at least, way more than using Nginx and CertBot). I initially installed it using this and this tutorial, but I didn't like it as the configuration was too complex and cumbersome.

Let's show how easy it can be to get it up and running with Caddy instead, so that we don't have to care about the renewal of certificates or complex configuration files.

First of all, we're running Ubuntu here.

I first stopped and disabled Nginx:

$ sudo systemctl stop nginx
$ sudo systemctl stop certbot
$ sudo systemctl stop certbot.timer

Let's first install Caddy itself:

$ sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https
$ curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo tee /etc/apt/trusted.gpg.d/caddy-stable.asc
$ curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-stable.list
$ sudo apt update
$ sudo apt install caddy

Next up is to edit the /etc/caddy/Caddyfile, adding the mysite.com website:

mysite.com, www.mysite.com {
        root * /var/www/mysite.com/public
        encode zstd gzip
        file_server
        php_fastcgi unix//var/run/php/php8.0-fpm.sock
}

Once that is done, all that is left to do is to restart Caddy:

$ sudo systemctl restart caddy

You can check if it's up-and-running like this:

$ sudo systemctl status caddy

That's it, it's as easy as that. All the rest is done automatically.

You can automate it slightly more by using snippets as explained here.

Related Posts

  • Setting up an NFS share on Linux
  • SSH Tunnel
  • Installing Packages from a file on Linux
  • Setting up and using an NFS share in Kubernetes
  • Uninstalling a .pkg file on mac