Skip to content

Commit

Permalink
docs: Caddyfile config adjustments (#345)
Browse files Browse the repository at this point in the history
  • Loading branch information
francislavoie authored Dec 8, 2023
1 parent 72d983e commit b9eae57
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 22 deletions.
47 changes: 25 additions & 22 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ RUN cp $PHP_INI_DIR/php.ini-production $PHP_INI_DIR/php.ini; \
sed -i 's/variables_order = "GPCS"/variables_order = "EGPCS"/' $PHP_INI_DIR/php.ini;
```

## Caddy Directives
## Caddyfile Config

To register the FrankenPHP executor, the `frankenphp` directive must be set in Caddy global options, then the `php_server` or the `php` HTTP directives must be set under routes serving PHP scripts.
To register the FrankenPHP executor, the `frankenphp` [global option](https://caddyserver.com/docs/caddyfile/concepts#global-options) must be set, then the `php_server` or the `php` [HTTP directives](https://caddyserver.com/docs/caddyfile/concepts#directives) may be used within the site blocks to serve your PHP app.

Minimal example:

Expand All @@ -39,7 +39,7 @@ localhost {
}
```

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

```caddyfile
{
Expand All @@ -56,7 +56,7 @@ Optionally, the number of threads to create and [worker scripts](worker.md) to s
# ...
```

Alternatively, the short form of the `worker` directive can also be used:
Alternatively, you may use the one-line short form of the `worker` option:

```caddyfile
{
Expand All @@ -79,12 +79,13 @@ You can also define multiple workers if you serve multiple apps on the same serv
}
app.example.com {
root /path/to/app/public/
root * /path/to/app/public
php_server
}
other.example.com {
root /path/to/other/public/
root * /path/to/other/public
php_server
}
...
```
Expand All @@ -95,22 +96,24 @@ but if you need full control, you can use the lower level `php` directive:
Using the `php_server` directive is equivalent to this configuration:

```caddyfile
# Add trailing slash for directory requests
@canonicalPath {
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
route {
# Add trailing slash for directory requests
@canonicalPath {
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
}
rewrite @indexFiles {http.matchers.file.relative}
# FrankenPHP!
@phpFiles path *.php
php @phpFiles
file_server
}
rewrite @indexFiles {http.matchers.file.relative}
# FrankenPHP!
@phpFiles path *.php
php @phpFiles
file_server
```

The `php_server` and the `php` directives have the following options:
Expand Down
2 changes: 2 additions & 0 deletions docs/laravel.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ Alternatively, you can run your Laravel projects with FrankenPHP from your local
# The domain name of your server
localhost {
# Set the webroot to the public/ dir
root * public/
# Enable compression (optional)
encode zstd gzip
# Execute PHP files in the current directory and serve assets
Expand Down

0 comments on commit b9eae57

Please sign in to comment.