diff --git a/caddy/php-server.go b/caddy/php-server.go index 69ab3df4e..99c01334e 100644 --- a/caddy/php-server.go +++ b/caddy/php-server.go @@ -107,7 +107,11 @@ func cmdPHPServer(fs caddycmd.Flags) (int, error) { if _, err := os.Stat("php.ini"); err == nil { iniScanDir := os.Getenv("PHP_INI_SCAN_DIR") - if err := os.Setenv("PHP_INI_SCAN_DIR", iniScanDir+":"+frankenphp.EmbeddedAppPath); err != nil { + newDir := frankenphp.EmbeddedAppPath + if iniScanDir != "" { + newDir = iniScanDir + ":" + newDir + } + if err := os.Setenv("PHP_INI_SCAN_DIR", newDir); err != nil { return caddy.ExitCodeFailedStartup, err } } diff --git a/docs/cn/config.md b/docs/cn/config.md index d20853c40..cb371c882 100644 --- a/docs/cn/config.md +++ b/docs/cn/config.md @@ -82,6 +82,27 @@ localhost { # ... ``` +Worker 块也可以在 `php` 或 `php_server` 块内定义。在这种情况下,worker 继承父指令的环境变量和根路径,并且只能由该特定域访问: + +```caddyfile +{ + frankenphp +} +example.com { + root /path/to/app + php_server { + root + worker { + file + num + env + watch + name + } + } +} +``` + 如果在同一服务器上运行多个应用,还可以定义多个 worker: ```caddyfile @@ -98,6 +119,7 @@ other.example.com { worker index.php } } + # ... ``` @@ -131,8 +153,8 @@ route { ```caddyfile php_server [] { - root # 设置站点的根目录。默认值:`root` 指令。 - split_path # 设置用于将 URI 拆分为两部分的子字符串。第一个匹配的子字符串将用于从路径中拆分"路径信息"。第一个部分以匹配的子字符串为后缀,并将假定为实际资源(CGI 脚本)名称。第二部分将设置为PATH_INFO,供脚本使用。默认值:`.php` + root # 设置站点的根目录。默认值:`root` 指令。如果未指定 + split_path # 设置用于将 URI 拆分为两部分的子字符串。第一个匹配的子字符串将用于从路径中拆分“路径信息”。第一个部分以匹配的子字符串为后缀,并将假定为实际资源(CGI 脚本)名称。第二部分将设置为PATH_INFO,供脚本使用。默认值:`.php` resolve_root_symlink false # 禁用将 `root` 目录在符号链接时将其解析为实际值(默认启用)。 env # 设置额外的环境变量,可以设置多个环境变量。 file_server off # 禁用内置的 file_server 指令。 @@ -157,10 +179,67 @@ php_server [] { ## PHP 配置 +您还可以使用 `frankenphp` 块中的 `php_ini` 指令更改 PHP 配置: + +```caddyfile +{ + frankenphp { + php_ini memory_limit 256M + + # 或者 + + php_ini { + memory_limit 256M + max_execution_time 15 + } + } +} +``` + 要加载 [其他 PHP INI 配置文件](https://www.php.net/manual/en/configuration.file.php#configuration.file.scan), 可以使用 `PHP_INI_SCAN_DIR` 环境变量。 设置后,PHP 将加载给定目录中存在 `.ini` 扩展名的所有文件。 +## php-server 命令 + +`php-server` 命令是启动生产就绪 PHP 服务器的便捷方式。它特别适用于快速部署、演示、开发或运行[嵌入式应用](embed.md)。 + +```console +frankenphp php-server [--domain ] [--root ] [--listen ] [--worker /path/to/worker.php<,nb-workers>] [--watch ] [--access-log] [--debug] [--no-compress] [--mercure] +``` + +### 选项 + +- `--domain`, `-d`: 提供文件的域名。如果指定,服务器将使用 HTTPS 并自动获取 Let's Encrypt 证书。 +- `--root`, `-r`: 站点根目录的路径。如果未指定并使用嵌入式应用,默认将使用 embedded_app/public 目录。 +- `--listen`, `-l`: 绑定监听器的地址。默认为 `:80`,如果指定了域名则为 `:443`。 +- `--worker`, `-w`: 要运行的 worker 脚本。可以多次指定以运行多个 worker。 +- `--watch`: 监视文件更改的目录。可以多次指定以监视多个目录。 +- `--access-log`, `-a`: 启用访问日志。 +- `--debug`, `-v`: 启用详细调试日志。 +- `--mercure`, `-m`: 启用内置的 Mercure.rocks hub。 +- `--no-compress`: 禁用 Zstandard、Brotli 和 Gzip 压缩。 + +### 示例 + +使用当前目录作为文档根目录启动服务器: + +```console +frankenphp php-server --root ./ +``` + +启动启用 HTTPS 的服务器: + +```console +frankenphp php-server --domain example.com +``` + +启动带有 worker 的服务器: + +```console +frankenphp php-server --worker public/index.php +``` + ## 启用调试模式 使用 Docker 镜像时,将 `CADDY_GLOBAL_OPTIONS` 环境变量设置为 `debug` 以启用调试模式: diff --git a/docs/cn/embed.md b/docs/cn/embed.md index 2a77ce0cd..ff2961390 100644 --- a/docs/cn/embed.md +++ b/docs/cn/embed.md @@ -39,6 +39,13 @@ composer install --ignore-platform-reqs --no-dev -a composer dump-env prod ``` +### 自定义配置 + +要自定义[配置](config.md),您可以在要嵌入的应用程序的主目录中放置 `Caddyfile` 和 `php.ini` 文件。 +如果嵌入了带有 Caddyfile 的应用程序,运行二进制文件时将自动使用该 Caddyfile 的配置。 + +如果您想直接从嵌入式应用程序目录提供文件,请指定 "root ./",因为不指定 root 选项将默认使用 embedded_app/public。 + ## 创建 Linux 二进制文件 创建 Linux 二进制文件的最简单方法是使用我们提供的基于 Docker 的构建器。 @@ -102,6 +109,12 @@ EMBED=/path/to/your/app \ ./my-app php-server ``` +默认情况下,如果未指定 root 选项,它将使用 embedded_app/public 目录作为文档根目录。如果您想直接从嵌入式应用程序目录提供服务,请指定 root 选项: + +```console +./my-app php-server --root ./ +``` + 如果您的应用包含 [worker 脚本](worker.md),请使用如下命令启动 worker: ```console diff --git a/docs/cn/worker.md b/docs/cn/worker.md index 053e4fdde..0ec65ce97 100644 --- a/docs/cn/worker.md +++ b/docs/cn/worker.md @@ -3,6 +3,45 @@ 启动应用程序一次并将其保存在内存中。 FrankenPHP 将在几毫秒内处理传入的请求。 +## Caddyfile 配置 + +Worker 块可以通过两种方式定义: + +在全局 frankenphp 块中,如[配置文档](config.md#caddyfile-config)中所述: + +```caddyfile +{ + frankenphp { + worker { + file <路径> + num <数量> + env <键> <值> + watch <路径> + name <名称> + } + } +} +``` + +在 php 或 php_server 块内: + +```caddyfile +example.com { + root /path/to/app + php_server { + worker { + file <路径> + num <数量> + env <键> <值> + watch <路径> + name <名称> + } + } +} +``` + +当在 php 或 php_server 块内定义时,worker 会继承父指令的环境变量和根路径,并且只能由该特定的 php 或 php_server 访问。 + ## 启动 Worker 脚本 ### Docker diff --git a/docs/config.md b/docs/config.md index 728591450..d9febbc8a 100644 --- a/docs/config.md +++ b/docs/config.md @@ -90,6 +90,27 @@ Alternatively, you may use the one-line short form of the `worker` option: # ... ``` +Worker blocks can also be defined inside a `php` or `php_server` block. In this case, the worker inherits environment variables and root path from the parent directive and is only accessible by that specific domain: + +```caddyfile +{ + frankenphp +} +example.com { + root /path/to/app + php_server { + root + worker { + file + num + env + watch + name + } + } +} +``` + You can also define multiple workers if you serve multiple apps on the same server: ```caddyfile @@ -213,7 +234,7 @@ This is an opt-in configuration that needs to be added to the global options in ```caddyfile { servers { - enable_full_duplex + enable_full_duplex } } ``` @@ -253,19 +274,59 @@ You can also change the PHP configuration using the `php_ini` directive in the ` ```caddyfile { - frankenphp { - php_ini memory_limit 256M + frankenphp { + php_ini memory_limit 256M - # or + # or - php_ini { - memory_limit 256M - max_execution_time 15 - } - } + php_ini { + memory_limit 256M + max_execution_time 15 + } + } } ``` +## The php-server Command + +The `php-server` command is a convenient way to start a production-ready PHP server. It's especially useful for quick deployments, demos, development, or to run an [embedded app](embed.md). + +```console +frankenphp php-server [--domain ] [--root ] [--listen ] [--worker /path/to/worker.php<,nb-workers>] [--watch ] [--access-log] [--debug] [--no-compress] [--mercure] +``` + +### Options + +- `--domain`, `-d`: Domain name at which to serve the files. If specified, the server will use HTTPS and automatically obtain a Let's Encrypt certificate. +- `--root`, `-r`: The path to the root of the site. If not specified and using an embedded app, it will use the embedded_app/public directory by default. +- `--listen`, `-l`: The address to which to bind the listener. Default is `:80` or `:443` if a domain is specified. +- `--worker`, `-w`: Worker script to run. Can be specified multiple times for multiple workers. +- `--watch`: Directory to watch for file changes. Can be specified multiple times for multiple directories. +- `--access-log`, `-a`: Enable the access log. +- `--debug`, `-v`: Enable verbose debug logs. +- `--mercure`, `-m`: Enable the built-in Mercure.rocks hub. +- `--no-compress`: Disable Zstandard, Brotli and Gzip compression. + +### Examples + +Start a server with the current directory as the document root: + +```console +frankenphp php-server --root ./ +``` + +Start a server with HTTPS enabled: + +```console +frankenphp php-server --domain example.com +``` + +Start a server with a worker: + +```console +frankenphp php-server --worker public/index.php +``` + ## Enable the Debug Mode When using the Docker image, set the `CADDY_GLOBAL_OPTIONS` environment variable to `debug` to enable the debug mode: diff --git a/docs/embed.md b/docs/embed.md index 7d18174fc..2e61fe8af 100644 --- a/docs/embed.md +++ b/docs/embed.md @@ -47,6 +47,10 @@ composer dump-env prod To customize [the configuration](config.md), you can put a `Caddyfile` as well as a `php.ini` file in the main directory of the app to be embedded (`$TMPDIR/my-prepared-app` in the previous example). +If an app with a Caddyfile in the directory is embedded, it will use that Caddyfile's configuration automatically when running the binary. + +If you want to serve files from the embedded app directly, specify "root ./", as not specifying the root option will serve embedded_app/public by default. + ## Creating a Linux Binary The easiest way to create a Linux binary is to use the Docker-based builder we provide. @@ -106,6 +110,12 @@ To start the web app run: ./my-app php-server ``` +By default, if no root option is specified, it will use the embedded_app/public directory as the document root. If you want to serve directly from the embedded app directory, specify the root option: + +```console +./my-app php-server --root ./ +``` + If your app contains a [worker script](worker.md), start the worker with something like: ```console diff --git a/docs/fr/config.md b/docs/fr/config.md index c43023fc3..1d23e16d5 100644 --- a/docs/fr/config.md +++ b/docs/fr/config.md @@ -47,10 +47,10 @@ Exemple minimal : ```caddyfile localhost { - # Activer la compression (optionnel) - encode zstd br gzip - # Exécuter les fichiers PHP dans le répertoire courant et servir les assets - php_server + # Activer la compression (optionnel) + encode zstd br gzip + # Exécuter les fichiers PHP dans le répertoire courant et servir les assets + php_server } ``` @@ -81,14 +81,35 @@ Vous pouvez également utiliser la forme courte de l'option worker en une seule ```caddyfile { - frankenphp { - worker - } + frankenphp { + worker + } } # ... ``` +Les blocs worker peuvent également être définis à l'intérieur d'un bloc `php` ou `php_server`. Dans ce cas, le worker hérite des variables d'environnement et du chemin racine de la directive parente et n'est accessible que par ce domaine spécifique : + +```caddyfile +{ + frankenphp +} +example.com { + root /path/to/app + php_server { + root + worker { + file + num + env + watch + name + } + } +} +``` + Vous pouvez aussi définir plusieurs workers si vous servez plusieurs applications sur le même serveur : ```caddyfile @@ -118,22 +139,22 @@ Utiliser la directive `php_server` est équivalent à cette configuration : ```caddyfile route { - # Ajoute un slash final pour les requêtes de répertoire - @canonicalPath { - file {path}/index.php - not path */ - } - redir @canonicalPath {path}/ 308 - # Si le fichier demandé n'existe pas, essayer les fichiers index - @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 + # Ajoute un slash final pour les requêtes de répertoire + @canonicalPath { + file {path}/index.php + not path */ + } + redir @canonicalPath {path}/ 308 + # Si le fichier demandé n'existe pas, essayer les fichiers index + @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 } ``` @@ -211,9 +232,9 @@ Il s'agit d'une configuration optionnelle qui doit être ajoutée aux options gl ```caddyfile { - servers { - enable_full_duplex - } + servers { + enable_full_duplex + } } ``` @@ -252,19 +273,59 @@ Vous pouvez également modifier la configuration de PHP en utilisant la directiv ```caddyfile { - frankenphp { - php_ini memory_limit 256M + frankenphp { + php_ini memory_limit 256M - # or + # or - php_ini { - memory_limit 256M - max_execution_time 15 - } - } + php_ini { + memory_limit 256M + max_execution_time 15 + } + } } ``` +## La commande php-server + +La commande `php-server` est un moyen pratique de démarrer un serveur PHP prêt pour la production. Elle est particulièrement utile pour les déploiements rapides, les démonstrations, le développement, ou pour exécuter une [application embarquée](embed.md). + +```console +frankenphp php-server [--domain ] [--root ] [--listen ] [--worker /path/to/worker.php<,nb-workers>] [--watch ] [--access-log] [--debug] [--no-compress] [--mercure] +``` + +### Options + +- `--domain`, `-d` : Nom de domaine sur lequel servir les fichiers. Si spécifié, le serveur utilisera HTTPS et obtiendra automatiquement un certificat Let's Encrypt. +- `--root`, `-r` : Chemin vers la racine du site. Si non spécifié et en utilisant une application embarquée, il utilisera le répertoire embedded_app/public par défaut. +- `--listen`, `-l` : L'adresse à laquelle lier l'écouteur. Par défaut, c'est `:80` ou `:443` si un domaine est spécifié. +- `--worker`, `-w` : Script worker à exécuter. Peut être spécifié plusieurs fois pour plusieurs workers. +- `--watch` : Répertoire à surveiller pour les changements de fichiers. Peut être spécifié plusieurs fois pour plusieurs répertoires. +- `--access-log`, `-a` : Activer le journal d'accès. +- `--debug`, `-v` : Activer les journaux de débogage détaillés. +- `--mercure`, `-m` : Activer le hub Mercure.rocks intégré. +- `--no-compress` : Désactiver la compression Zstandard, Brotli et Gzip. + +### Exemples + +Démarrer un serveur avec le répertoire courant comme racine de document : + +```console +frankenphp php-server --root ./ +``` + +Démarrer un serveur avec HTTPS activé : + +```console +frankenphp php-server --domain example.com +``` + +Démarrer un serveur avec un worker : + +```console +frankenphp php-server --worker public/index.php +``` + ## Activer le mode debug Lors de l'utilisation de l'image Docker, définissez la variable d'environnement `CADDY_GLOBAL_OPTIONS` sur `debug` pour activer le mode debug : diff --git a/docs/fr/embed.md b/docs/fr/embed.md index cd51def77..c20a5117f 100644 --- a/docs/fr/embed.md +++ b/docs/fr/embed.md @@ -48,6 +48,9 @@ Pour personnaliser [la configuration](config.md), vous pouvez mettre un fichier `Caddyfile` ainsi qu'un fichier `php.ini` dans le répertoire principal de l'application à intégrer (`$TMPDIR/my-prepared-app` dans l'exemple précédent). +Si une application avec un Caddyfile dans le répertoire est intégrée, elle utilisera automatiquement la configuration de ce Caddyfile lors de l'exécution du binaire. + +Si vous souhaitez servir des fichiers directement depuis l'application embarquée, spécifiez « root ./ », car ne pas spécifier l'option root servira embedded_app/public par défaut. ## Créer un binaire Linux @@ -108,6 +111,12 @@ Pour démarrer l'application web, exécutez : ./my-app php-server ``` +Par défaut, si aucune option root n'est spécifiée, il utilisera le répertoire embedded_app/public comme racine de document. Si vous souhaitez servir directement depuis le répertoire de l'application embarquée, spécifiez l'option root : + +```console +./my-app php-server --root ./ +``` + Si votre application contient un [script worker](worker.md), démarrez le worker avec quelque chose comme : ```console diff --git a/docs/fr/worker.md b/docs/fr/worker.md index e79d355da..4a163ab55 100644 --- a/docs/fr/worker.md +++ b/docs/fr/worker.md @@ -3,6 +3,45 @@ Démarrez votre application une fois et gardez-la en mémoire. FrankenPHP traitera les requêtes entrantes en quelques millisecondes. +## Configuration du Caddyfile + +Les blocs worker peuvent être définis de deux manières : + +Dans le bloc global frankenphp, comme décrit dans la [documentation de configuration](config.md#configuration-du-caddyfile) : + +```caddyfile +{ + frankenphp { + worker { + file + num + env + watch + name + } + } +} +``` + +À l'intérieur d'un bloc php ou php_server : + +```caddyfile +example.com { + root /path/to/app + php_server { + worker { + file + num + env + watch + name + } + } +} +``` + +Lorsqu'il est défini à l'intérieur d'un bloc php ou php_server, le worker hérite des variables d'environnement et du chemin racine de la directive parente et n'est accessible que par ce php ou php_server spécifique. + ## Démarrage des scripts workers ### Docker diff --git a/docs/ru/config.md b/docs/ru/config.md index 2ca733597..2611aeebb 100644 --- a/docs/ru/config.md +++ b/docs/ru/config.md @@ -85,6 +85,27 @@ localhost { # ... ``` +Блоки worker также могут быть определены внутри блока `php` или `php_server`. В этом случае worker наследует переменные окружения и корневой путь от родительской директивы и доступен только для этого конкретного домена: + +```caddyfile +{ + frankenphp +} +example.com { + root /path/to/app + php_server { + root + worker { + file + num + env + watch + name + } + } +} +``` + Вы также можете определить несколько workers, если обслуживаете несколько приложений на одном сервере: ```caddyfile @@ -199,9 +220,9 @@ php_server [] { ```caddyfile { - servers { - enable_full_duplex - } + servers { + enable_full_duplex + } } ``` @@ -232,9 +253,66 @@ CADDY_GLOBAL_OPTIONS="servers { ## Конфигурация PHP +Вы также можете изменить конфигурацию PHP, используя директиву `php_ini` в блоке `frankenphp`: + +```caddyfile +{ + frankenphp { + php_ini memory_limit 256M + + # или + + php_ini { + memory_limit 256M + max_execution_time 15 + } + } +} +``` + Для загрузки [дополнительных конфигурационных файлов PHP](https://www.php.net/manual/en/configuration.file.php#configuration.file.scan) можно использовать переменную окружения `PHP_INI_SCAN_DIR`. Если она установлена, PHP загрузит все файлы с расширением `.ini`, находящиеся в указанных директориях. +## Команда php-server + +Команда `php-server` — это удобный способ запустить готовый к продакшну PHP-сервер. Она особенно полезна для быстрого развертывания, демонстраций, разработки или запуска [встроенного приложения](embed.md). + +```console +frankenphp php-server [--domain ] [--root ] [--listen ] [--worker /path/to/worker.php<,nb-workers>] [--watch ] [--access-log] [--debug] [--no-compress] [--mercure] +``` + +### Опции + +- `--domain`, `-d`: Доменное имя, на котором будут обслуживаться файлы. Если указано, сервер будет использовать HTTPS и автоматически получит сертификат Let's Encrypt. +- `--root`, `-r`: Путь к корневой директории сайта. Если не указано и используется встроенное приложение, по умолчанию будет использоваться директория embedded_app/public. +- `--listen`, `-l`: Адрес, к которому будет привязан слушатель. По умолчанию `:80` или `:443`, если указан домен. +- `--worker`, `-w`: Скрипт worker для запуска. Может быть указан несколько раз для нескольких workers. +- `--watch`: Директория для отслеживания изменений файлов. Может быть указана несколько раз для нескольких директорий. +- `--access-log`, `-a`: Включить журнал доступа. +- `--debug`, `-v`: Включить подробные журналы отладки. +- `--mercure`, `-m`: Включить встроенный хаб Mercure.rocks. +- `--no-compress`: Отключить сжатие Zstandard, Brotli и Gzip. + +### Примеры + +Запуск сервера с текущей директорией в качестве корневой: + +```console +frankenphp php-server --root ./ +``` + +Запуск сервера с включенным HTTPS: + +```console +frankenphp php-server --domain example.com +``` + +Запуск сервера с worker: + +```console +frankenphp php-server --worker public/index.php +``` + ## Включение режима отладки При использовании Docker-образа установите переменную окружения `CADDY_GLOBAL_OPTIONS` в `debug`, чтобы включить режим отладки: diff --git a/docs/ru/embed.md b/docs/ru/embed.md index 2c6092183..7a10e7581 100644 --- a/docs/ru/embed.md +++ b/docs/ru/embed.md @@ -44,6 +44,9 @@ composer dump-env prod ### Настройка конфигурации Чтобы настроить [конфигурацию](config.md), вы можете разместить файлы `Caddyfile` и `php.ini` в основной директории приложения (`$TMPDIR/my-prepared-app` в примере выше). +Если приложение с файлом Caddyfile в директории встроено, оно будет автоматически использовать конфигурацию из этого Caddyfile при запуске бинарного файла. + +Если вы хотите обслуживать файлы непосредственно из встроенного приложения, укажите "root ./", так как без указания опции root по умолчанию будет использоваться embedded_app/public. ## Создание бинарного файла для Linux @@ -104,6 +107,12 @@ EMBED=/path/to/your/app ./build-static.sh ./my-app php-server ``` +По умолчанию, если опция root не указана, будет использоваться директория embedded_app/public в качестве корневой. Если вы хотите обслуживать файлы непосредственно из директории встроенного приложения, укажите опцию root: + +```console +./my-app php-server --root ./ +``` + Если ваше приложение содержит [worker-скрипт](worker.md), запустите его следующим образом: ```console diff --git a/docs/ru/worker.md b/docs/ru/worker.md index 86a20a53e..48421843e 100644 --- a/docs/ru/worker.md +++ b/docs/ru/worker.md @@ -3,6 +3,45 @@ Загрузите приложение один раз и держите его в памяти. FrankenPHP обрабатывает входящие запросы за несколько миллисекунд. +## Конфигурация Caddyfile + +Блоки worker могут быть определены двумя способами: + +В глобальном блоке frankenphp, как описано в [документации по конфигурации](config.md#конфигурация-caddyfile): + +```caddyfile +{ + frankenphp { + worker { + file <путь> + num <количество> + env <ключ> <значение> + watch <путь> + name <имя> + } + } +} +``` + +Внутри блока php или php_server: + +```caddyfile +example.com { + root /path/to/app + php_server { + worker { + file <путь> + num <количество> + env <ключ> <значение> + watch <путь> + name <имя> + } + } +} +``` + +Когда блок worker определен внутри блока php или php_server, он наследует переменные окружения и корневой путь от родительской директивы и доступен только для этого конкретного php или php_server. + ## Запуск worker-скриптов ### Docker diff --git a/docs/tr/config.md b/docs/tr/config.md index cf19a2ca3..0d16616d9 100644 --- a/docs/tr/config.md +++ b/docs/tr/config.md @@ -84,6 +84,27 @@ Alternatif olarak, `worker` seçeneğinin tek satırlık kısa formunu kullanabi # ... ``` +Worker blokları ayrıca bir `php` veya `php_server` bloğu içinde de tanımlanabilir. Bu durumda, worker, üst yönergenin ortam değişkenlerini ve kök yolunu devralır ve yalnızca o belirli alan tarafından erişilebilir: + +```caddyfile +{ + frankenphp +} +example.com { + root /path/to/app + php_server { + root + worker { + file + num + env + watch + name + } + } +} +``` + Aynı sunucuda birden fazla uygulamaya hizmet veriyorsanız birden fazla işçi de tanımlayabilirsiniz: ```caddyfile @@ -164,10 +185,67 @@ FPM ve CLI SAPI'lerinde olduğu gibi, ortam değişkenleri varsayılan olarak `$ ## PHP konfigürasyonu +Ayrıca `frankenphp` bloğundaki `php_ini` yönergesini kullanarak PHP yapılandırmasını değiştirebilirsiniz: + +```caddyfile +{ + frankenphp { + php_ini memory_limit 256M + + # veya + + php_ini { + memory_limit 256M + max_execution_time 15 + } + } +} +``` + Ek olarak [PHP yapılandırma dosyalarını](https://www.php.net/manual/en/configuration.file.php#configuration.file.scan) yüklemek için `PHP_INI_SCAN_DIR` ortam değişkeni kullanılabilir. Ayarlandığında, PHP verilen dizinlerde bulunan `.ini` uzantılı tüm dosyaları yükleyecektir. +## php-server Komutu + +`php-server` komutu, üretime hazır bir PHP sunucusu başlatmanın uygun bir yoludur. Özellikle hızlı dağıtımlar, demolar, geliştirme veya [gömülü bir uygulama](embed.md) çalıştırmak için kullanışlıdır. + +```console +frankenphp php-server [--domain ] [--root ] [--listen ] [--worker /path/to/worker.php<,nb-workers>] [--watch ] [--access-log] [--debug] [--no-compress] [--mercure] +``` + +### Seçenekler + +- `--domain`, `-d`: Dosyaların sunulacağı alan adı. Belirtilirse, sunucu HTTPS kullanacak ve otomatik olarak bir Let's Encrypt sertifikası alacaktır. +- `--root`, `-r`: Sitenin kök dizininin yolu. Belirtilmezse ve gömülü bir uygulama kullanılıyorsa, varsayılan olarak embedded_app/public dizinini kullanacaktır. +- `--listen`, `-l`: Dinleyicinin bağlanacağı adres. Varsayılan olarak `:80` veya bir alan adı belirtilmişse `:443`'tür. +- `--worker`, `-w`: Çalıştırılacak worker betiği. Birden fazla worker için birden çOK kez belirtilebilir. +- `--watch`: Dosya değişikliklerini izlemek için dizin. Birden fazla dizin için birden çOK kez belirtilebilir. +- `--access-log`, `-a`: Erişim günlüğünü etkinleştirin. +- `--debug`, `-v`: Ayrıntılı hata ayıklama günlüklerini etkinleştirin. +- `--mercure`, `-m`: Yerleşik Mercure.rocks hub'ını etkinleştirin. +- `--no-compress`: Zstandard, Brotli ve Gzip sıkıştırmasını devre dışı bırakın. + +### Örnekler + +Geçerli dizini belge kökü olarak kullanarak bir sunucu başlatın: + +```console +frankenphp php-server --root ./ +``` + +HTTPS etkin bir sunucu başlatın: + +```console +frankenphp php-server --domain example.com +``` + +Bir worker ile sunucu başlatın: + +```console +frankenphp php-server --worker public/index.php +``` + ## Hata Ayıklama Modunu Etkinleştirin Docker imajını kullanırken, hata ayıklama modunu etkinleştirmek için `CADDY_GLOBAL_OPTIONS` ortam değişkenini `debug` olarak ayarlayın: diff --git a/docs/tr/embed.md b/docs/tr/embed.md index c76b545f7..16e3f78dc 100644 --- a/docs/tr/embed.md +++ b/docs/tr/embed.md @@ -39,6 +39,14 @@ composer install --ignore-platform-reqs --no-dev -a composer dump-env prod ``` +### Yapılandırmayı Özelleştirme + +[Yapılandırmayı](config.md) özelleştirmek için, gömülecek uygulamanın ana dizinine bir `Caddyfile` ve bir `php.ini` dosyası koyabilirsiniz +(önceki örnekte `$TMPDIR/my-prepared-app`). +Dizinde bir Caddyfile ile bir uygulama gömülürse, binary dosyasını çalıştırırken otomatik olarak bu Caddyfile'ın yapılandırmasını kullanacaktır. + +Gömülü uygulamadan dosyaları doğrudan sunmak istiyorsanız, "root ./" belirtin, çünkü root seçeneğini belirtmemek varsayılan olarak embedded_app/public dizininden sunacaktır. + ## Linux Binary'si Oluşturma Bir Linux binary çıktısı almanın en kolay yolu, sağladığımız Docker tabanlı derleyiciyi kullanmaktır. @@ -102,6 +110,12 @@ Web uygulamasını başlatmak için çalıştırın: ./my-app php-server ``` +Varsayılan olarak, eğer root seçeneği belirtilmezse, belge kökü olarak embedded_app/public dizinini kullanacaktır. Doğrudan gömülü uygulama dizininden sunmak istiyorsanız, root seçeneğini belirtin: + +```console +./my-app php-server --root ./ +``` + Uygulamanız bir [worker betiği](worker.md) içeriyorsa, worker'ı aşağıdaki gibi bir şeyle başlatın: ```console diff --git a/docs/worker.md b/docs/worker.md index 31432695a..a09115cbb 100644 --- a/docs/worker.md +++ b/docs/worker.md @@ -3,6 +3,47 @@ Boot your application once and keep it in memory. FrankenPHP will handle incoming requests in a few milliseconds. +## Caddyfile Config + +For detailed information on how to specify workers in your configuration, see the [configuration documentation](config.md#caddyfile-config). + +Worker blocks can be defined in two ways: + +In the global frankenphp block, as described in the [configuration documentation](config.md#caddyfile-config): + +```caddyfile +{ + frankenphp { + worker { + file + num + env + watch + name + } + } +} +``` + +Inside a php or php_server block: + +```caddyfile +example.com { + root /path/to/app + php_server { + worker { + file + num + env + watch + name + } + } +} +``` + +When defined inside a php or php_server block, the worker inherits environment variables and root path from the parent directive and is only accessible by that specific php or php_server. + ## Starting Worker Scripts ### Docker