From b9eae571e514b1fde918e9e448835b3223225a81 Mon Sep 17 00:00:00 2001 From: Francis Lavoie Date: Fri, 8 Dec 2023 13:09:20 -0500 Subject: [PATCH] docs: Caddyfile config adjustments (#345) --- docs/config.md | 47 +++++++++++++++++++++++++---------------------- docs/laravel.md | 2 ++ 2 files changed, 27 insertions(+), 22 deletions(-) diff --git a/docs/config.md b/docs/config.md index c1983df95..71f538607 100644 --- a/docs/config.md +++ b/docs/config.md @@ -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: @@ -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 { @@ -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 { @@ -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 } ... ``` @@ -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: diff --git a/docs/laravel.md b/docs/laravel.md index b1b31860d..f0754cada 100644 --- a/docs/laravel.md +++ b/docs/laravel.md @@ -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