Caddy

Caddy Web Server

After creating a systemd service run the following

sudo systemctl daemon-reload

Then these commands as necessary:

  • sudo systemctl enable caddy
  • sudo systemctl start caddy
  • sudo systemctl stop caddy
  • sudo systemctl reload caddy (after a config change saves restarting)

The Caddyfile is in /etc/caddy

php

sudo systemctl start php-fpm.service

The Caddyfile needs this line

php_fastcgi unix//run/php/php8.2-fpm.sock

Permission denied or blank screen So you could either use a totally different folder like /srv or /var/www or the dir need to be executable chmod +x for caddy user

Basic Authentication

Setting up with Caddyfile

Generate a hash of your password

Enter this into the terminal to generate a password hash (This uses the bcrypt hashing algorithm by default):

caddy hash-password

Output Example:
JDJhJDE0JElab2ZPM25zdU40bE5SSURlTHd3OHVBeVJvYTlMN3dMOEFMdFVCRzNYS1l5ODl6TlVyQllH
Caddyfile Below is a template just replace the Username and Hash, then place it in your Caddyfile.
basicauth * {
    bob JDJhJDE0JElab2ZPM25zdU40bE5SSURlTHd3OHVBeVJvYTlMN3dMOEFMdFVCRzNYS1l5ODl6TlVyQllH
}
If you want to secure a certain path, the following syntax can be used:
basicauth /homework/* {
    bob JDJhJDE0JElab2ZPM25zdU40bE5SSURlTHd3OHVBeVJvYTlMN3dMOEFMdFVCRzNYS1l5ODl6TlVyQllH
}
Reload Caddy
caddy reload
or
sudo systemctl reload caddy