Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify Caddyfile for Laravel Octane #923

Open
jduan00 opened this issue Jul 15, 2024 · 3 comments
Open

Modify Caddyfile for Laravel Octane #923

jduan00 opened this issue Jul 15, 2024 · 3 comments
Labels
enhancement New feature or request

Comments

@jduan00
Copy link

jduan00 commented Jul 15, 2024

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.

  1. Make a copy for the Caddyfile
    cp <laravel path>/vendor/laravel/octane/src/Commands/stubs/Caddyfile /etc/frankenphp/Caddyfile-octane

  2. 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
    }
}
  1. 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
@jduan00 jduan00 added the enhancement New feature or request label Jul 15, 2024
@withinboredom
Copy link
Collaborator

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.

@jduan00
Copy link
Author

jduan00 commented Jul 16, 2024

Thanks for the pointer. It seems that using the --caddyfile option will lose CADDY_SERVER_SERVER_NAME and other variables.

@AlliBalliBaba
Copy link
Contributor

AlliBalliBaba commented Jul 26, 2024

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
		}
	}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants