A Caddy config file for PHP Applications

Mattias Geniar shared his Caddyfile – a config file for the high promising Caddy Webserver – for use with a Laravel backed website. His config file takes care of all of these:

  • Redirect all versions of the domain to domain.tld, without the www-prefix
  • Enable gzip compression
  • Store logs in the home dir of the site, rotate them and keep 14 versions
  • Point all PHP requests to an upstream socket, served by php-fpm
  • Redirect all URLs to the index.php (for pretty-printed URLs)
  • Prevent access to files like .htaccess, .git, … (like domain.tld/.htaccess)
  • Set a sane set of default security headers, like HSTS (force HTTPS)

This Caddyfile looks so simple that you could easily take the official php:7.4.1-fpm Docker Image, install Caddy into it and be on your way.

A Caddyfile config example for Laravel →