Modify Caddyfile for Laravel Octane
Describe you feature request
Hi there,
I am trying to tweak the Caddyfile for Laravel Octane. What is the proper way to do it?
Here is what I have tried, but the server does not start. Any help will be greatly appreciated.
-
Make a copy for the Caddyfile
cp <laravel path>/vendor/laravel/octane/src/Commands/stubs/Caddyfile /etc/frankenphp/Caddyfile-octane -
Modify Caddyfile-octane
# Based on /app/www/sites/eid5/vendor/laravel/octane/src/Commands/stubs/Caddyfile
{
{$CADDY_GLOBAL_OPTIONS}
## admin {$CADDY_SERVER_ADMIN_HOST}:{$CADDY_SERVER_ADMIN_PORT}
admin off
frankenphp {
worker "{$APP_PUBLIC_PATH}/frankenphp-worker.php" {$CADDY_SERVER_WORKER_COUNT}
}
}
{$CADDY_SERVER_SERVER_NAME} {
log {
level INFO
output stdout
format json
# Redact the authorization query parameter that can be set by Mercure...
format filter {
wrap {$CADDY_SERVER_LOGGER}
fields {
uri query {
replace authorization REDACTED
}
}
}
}
route {
root * "{$APP_PUBLIC_PATH}"
## encode zstd br gzip ## these will add 4ms latency
# Mercure configuration is injected here...
{$CADDY_SERVER_EXTRA_DIRECTIVES}
php_server {
index frankenphp-worker.php
# Required for the public/storage/ directory...
resolve_root_symlink
}
}
}
# Add docker health check
127.0.0.1:8080 {
respond /http-ping "pong" 200
log {
output discard
}
}
- Start laravel octane + frankenphp
php artisan octane:start --server=frankenphp --port=8100 --host=0.0.0.0 --caddyfile /etc/frankenphp/Caddyfile-octane
Error received:
Error: adapting config using caddyfile: server block without any key is global configuration, and if used, it must be first
I suspect CADDY_SERVER_SERVER_NAME is empty and it sees two global blocks. At least, that is what the error message you gave says is wrong.
Thanks for the pointer. It seems that using the --caddyfile option will lose CADDY_SERVER_SERVER_NAME and other variables.
I don't think $CADDY_SERVER_SERVER_NAME is necessarily dropped. This example configuration works for me, at least for laravel/octane v2.4.0 laravel/framework v11.10.0:
php artisan octane:start --server=frankenphp --host=0.0.0.0 --port=8000 --max-requests=10000 --caddyfile=/app/resources/caddy/backend.Caddyfile
The backend.Caddyfile content:
{
{$CADDY_GLOBAL_OPTIONS}
admin localhost:{$CADDY_SERVER_ADMIN_PORT}
frankenphp {
worker "{$APP_PUBLIC_PATH}/frankenphp-worker.php" {$CADDY_SERVER_WORKER_COUNT}
}
}
{$CADDY_SERVER_SERVER_NAME} {
log {
level {$CADDY_SERVER_LOG_LEVEL}
# Redact the authorization query parameter that can be set by Mercure...
format filter {
wrap {$CADDY_SERVER_LOGGER}
fields {
uri query {
replace authorization REDACTED
}
}
}
}
route {
root * "{$APP_PUBLIC_PATH}"
encode zstd br gzip
# Mercure configuration is injected here...
{$CADDY_SERVER_EXTRA_DIRECTIVES}
@static {
file
path *.ico *.css *.js *.gif *.jpg *.jpeg *.png *.svg *.woff *.woff2 *ttf *.svg
}
header @static Cache-Control max-age=5184000
php_server {
index frankenphp-worker.php
# Required for the public/storage/ directory...
# resolve_root_symlink
}
}
}
Has anyone managed to modify the Caddyfile when using FrankenPHP with Octane?
I tried to make changes, but when I pass the Caddyfile using the --caddyfile=path/Caddyfile parameter, it starts throwing certificate errors. I even tried setting a fixed domain, but the error persists.
If anyone can help, I’d really appreciate it.