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

feat: minor improvements to the default Caddyfile #272

Merged
merged 1 commit into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions caddy/frankenphp/Caddyfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
#worker /path/to/your/worker.php
{$FRANKENPHP_CONFIG}
}

# https://caddyserver.com/docs/caddyfile/directives#sorting-algorithm
order mercure after encode
order vulcain after reverse_proxy
order php_server before file_server
order php before file_server
}

{$CADDY_EXTRA_CONFIG}
Expand Down
68 changes: 34 additions & 34 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,32 +25,32 @@ Minimal example:

```caddyfile
{
# Enable FrankenPHP
frankenphp
# Configure when the directive must be executed
order php_server before file_server
# Enable FrankenPHP
frankenphp
# Configure when the directive must be executed
order php_server before file_server
}

localhost {
# Enable compression (optional)
encode zstd gzip
# Execute PHP files in the current directory and serve assets
php_server
# Enable compression (optional)
encode zstd gzip
# Execute PHP files in the current directory and serve assets
php_server
}
```

Optionally, the number of threads to create and [worker scripts](worker.md) to start with the server can be specified under the global directive.

```caddyfile
{
frankenphp {
num_threads <num_threads> # Sets the number of PHP threads to start. Default: 2x the number of available CPUs.
worker {
file <path> # Sets the path to the worker script.
num <num> # Sets the number of PHP threads to start, defaults to 2x the number of available CPUs.
env <key> <value> # Sets an extra environment variable to the given value. Can be specified more than once for multiple environment variables.
}
}
frankenphp {
num_threads <num_threads> # Sets the number of PHP threads to start. Default: 2x the number of available CPUs.
worker {
file <path> # Sets the path to the worker script.
num <num> # Sets the number of PHP threads to start, defaults to 2x the number of available CPUs.
env <key> <value> # Sets an extra environment variable to the given value. Can be specified more than once for multiple environment variables.
}
}
}

# ...
Expand All @@ -60,31 +60,31 @@ Alternatively, the short form of the `worker` directive can also be used:

```caddyfile
{
frankenphp {
worker <file> <num>
}
frankenphp {
worker <file> <num>
}
}

# ...
```

You can also define multiple workers if you serve multiple apps on the same server:

```caddyfile
{
frankenphp {
worker /path/to/app/public/index.php <num>
worker /path/to/other/public/index.php <num>
}
frankenphp {
worker /path/to/app/public/index.php <num>
worker /path/to/other/public/index.php <num>
}
}

app.example.com {
root /path/to/app/public/
root /path/to/app/public/
}


other.example.com {
root /path/to/other/public/
root /path/to/other/public/
}
...
```
Expand All @@ -97,14 +97,14 @@ Using the `php_server` directive is equivalent to this configuration:
```caddyfile
# Add trailing slash for directory requests
@canonicalPath {
file {path}/index.php
not path */
file {path}/index.php
not path */
}
redir @canonicalPath {path}/ 308
# If the requested file does not exist, try index files
@indexFiles file {
try_files {path} {path}/index.php index.php
split_path .php
try_files {path} {path}/index.php index.php
split_path .php
}
rewrite @indexFiles {http.matchers.file.relative}
# FrankenPHP!
Expand All @@ -117,10 +117,10 @@ The `php_server` and the `php` directives have the following options:

```caddyfile
php_server [<matcher>] {
root <directory> # Sets the root folder to the site. Default: `root` directive.
split_path <delim...> # Sets the substrings for splitting the URI into two parts. The first matching substring will be used to split the "path info" from the path. The first piece is suffixed with the matching substring and will be assumed as the actual resource (CGI script) name. The second piece will be set to PATH_INFO for the CGI script to use. Default: `.php`
resolve_root_symlink # Enables resolving the `root` directory to its actual value by evaluating a symbolic link, if one exists.
env <key> <value> # Sets an extra environment variable to the given value. Can be specified more than once for multiple environment variables.
root <directory> # Sets the root folder to the site. Default: `root` directive.
split_path <delim...> # Sets the substrings for splitting the URI into two parts. The first matching substring will be used to split the "path info" from the path. The first piece is suffixed with the matching substring and will be assumed as the actual resource (CGI script) name. The second piece will be set to PATH_INFO for the CGI script to use. Default: `.php`
resolve_root_symlink # Enables resolving the `root` directory to its actual value by evaluating a symbolic link, if one exists.
env <key> <value> # Sets an extra environment variable to the given value. Can be specified more than once for multiple environment variables.
}
```

Expand Down