Skip to content

Instantly share code, notes, and snippets.

@cheeze2000
Last active January 1, 2023 10:09
Show Gist options
  • Save cheeze2000/301749c1345e496738a01c412dbf343e to your computer and use it in GitHub Desktop.
Save cheeze2000/301749c1345e496738a01c412dbf343e to your computer and use it in GitHub Desktop.
Laravel + Caddy

PHP 8.1, Laravel 9.x, Caddy 2.x

Assume your Laravel project is in /home/cheeze/my-app/, make sure www-data has access to ./storage and ./bootstrap/cache/ with:

  • sudo chown -R www-data:www-data storage
  • sudo chown -R www-data:www-data bootstrap/cache

This is because Caddy needs write access to the logs inside these folders.

If you want to host this laravel app on https://laravel.example.com,

# /etc/caddy/Caddyfile
laravel.example.com {
    root * /home/cheeze/my-app/public           # IMPORTANT! NOT /home/cheeze/my-app/
    encode zstd gzip                            # enable Zstandard and Gzip compression
    file_server
    php_fastcgi unix//run/php/php8.1-fpm.sock   # remember to install `php8.1-fpm`
}
  1. Restart Caddy after editing Caddyfile
  2. Remember to run npm run build and bootstrap/ssr/ssr.mjs

In Arch, make sure to add the caddy user to http group. www-data is now http.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment