Skip to content

Commit d072ab2

Browse files
committed
add documentation about the php-server command
1 parent e8fb4f8 commit d072ab2

10 files changed

Lines changed: 235 additions & 5 deletions

File tree

docs/cn/config.md

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ route {
138138

139139
```caddyfile
140140
php_server [<matcher>] {
141-
root <directory> # 设置站点的根目录。默认值:`root` 指令。
141+
root <directory> # 设置站点的根目录。默认值:`root` 指令。如果未指定,默认将使用 current_working_dir/public 目录。
142142
split_path <delim...> # 设置用于将 URI 拆分为两部分的子字符串。第一个匹配的子字符串将用于从路径中拆分“路径信息”。第一个部分以匹配的子字符串为后缀,并将假定为实际资源(CGI 脚本)名称。第二部分将设置为PATH_INFO,供脚本使用。默认值:`.php`
143143
resolve_root_symlink false # 禁用将 `root` 目录在符号链接时将其解析为实际值(默认启用)。
144144
env <key> <value> # 设置额外的环境变量,可以设置多个环境变量。
@@ -159,6 +159,43 @@ php_server [<matcher>] {
159159
可以使用 `PHP_INI_SCAN_DIR` 环境变量。
160160
设置后,PHP 将加载给定目录中存在 `.ini` 扩展名的所有文件。
161161

162+
## php-server 命令
163+
164+
`php-server` 命令是启动生产就绪 PHP 服务器的便捷方式。它特别适用于快速部署、演示、开发或运行[嵌入式应用](embed.md)
165+
166+
```console
167+
frankenphp php-server [--domain <example.com>] [--root <path>] [--listen <addr>] [--worker /path/to/worker.php<,nb-workers>] [--watch <paths...>] [--access-log] [--debug] [--no-compress] [--mercure]
168+
```
169+
170+
### 选项
171+
172+
- `--domain`, `-d`: 提供文件的域名。如果指定,服务器将使用 HTTPS 并自动获取 Let's Encrypt 证书。
173+
- `--root`, `-r`: 站点根目录的路径。如果未指定并使用嵌入式应用,默认将使用 embedded_app/public 目录。
174+
- `--listen`, `-l`: 绑定监听器的地址。默认为 `:80`,如果指定了域名则为 `:443`
175+
- `--worker`, `-w`: 要运行的 worker 脚本。可以多次指定以运行多个 worker。
176+
- `--watch`: 监视文件更改的目录。可以多次指定以监视多个目录。
177+
- `--access-log`, `-a`: 启用访问日志。
178+
- `--debug`, `-v`: 启用详细调试日志。
179+
- `--mercure`, `-m`: 启用内置的 Mercure.rocks hub。
180+
- `--no-compress`: 禁用 Zstandard、Brotli 和 Gzip 压缩。
181+
182+
### 示例
183+
184+
使用当前目录作为文档根目录启动服务器:
185+
```console
186+
frankenphp php-server --root ./
187+
```
188+
189+
启动启用 HTTPS 的服务器:
190+
```console
191+
frankenphp php-server --domain example.com
192+
```
193+
194+
启动带有 worker 的服务器:
195+
```console
196+
frankenphp php-server --worker public/index.php
197+
```
198+
162199
## 启用调试模式
163200

164201
使用 Docker 镜像时,将 `CADDY_GLOBAL_OPTIONS` 环境变量设置为 `debug` 以启用调试模式:

docs/cn/embed.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ composer install --ignore-platform-reqs --no-dev -a
3939
composer dump-env prod
4040
```
4141

42+
### 自定义配置
43+
44+
要自定义[配置](config.md),您可以在要嵌入的应用程序的主目录中放置 `Caddyfile``php.ini` 文件。
45+
如果嵌入了带有 Caddyfile 的应用程序,运行二进制文件时将自动使用该 Caddyfile 的配置。
46+
4247
## 创建 Linux 二进制文件
4348

4449
创建 Linux 二进制文件的最简单方法是使用我们提供的基于 Docker 的构建器。
@@ -102,6 +107,12 @@ EMBED=/path/to/your/app \
102107
./my-app php-server
103108
```
104109

110+
默认情况下,如果未指定 root 选项,它将使用 embedded_app/public 目录作为文档根目录。如果您想直接从嵌入式应用程序目录提供服务,请指定 root 选项:
111+
112+
```console
113+
./my-app php-server --root ./
114+
```
115+
105116
如果您的应用包含 [worker 脚本](worker.md),请使用如下命令启动 worker:
106117

107118
```console

docs/config.md

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ The `php_server` and the `php` directives have the following options:
149149

150150
```caddyfile
151151
php_server [<matcher>] {
152-
root <directory> # Sets the root folder to the site. Default: `root` directive.
152+
root <directory> # Sets the root folder to the site. Default: `root` directive. If not specified, it will use the current_working_dir/public directory by default.
153153
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 script to use. Default: `.php`
154154
resolve_root_symlink false # Disables resolving the `root` directory to its actual value by evaluating a symbolic link, if one exists (enabled by default).
155155
env <key> <value> # Sets an extra environment variable to the given value. Can be specified more than once for multiple environment variables.
@@ -265,6 +265,43 @@ You can also change the PHP configuration using the `php_ini` directive in the `
265265
}
266266
```
267267

268+
## The php-server Command
269+
270+
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).
271+
272+
```console
273+
frankenphp php-server [--domain <example.com>] [--root <path>] [--listen <addr>] [--worker /path/to/worker.php<,nb-workers>] [--watch <paths...>] [--access-log] [--debug] [--no-compress] [--mercure]
274+
```
275+
276+
### Options
277+
278+
- `--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.
279+
- `--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.
280+
- `--listen`, `-l`: The address to which to bind the listener. Default is `:80` or `:443` if a domain is specified.
281+
- `--worker`, `-w`: Worker script to run. Can be specified multiple times for multiple workers.
282+
- `--watch`: Directory to watch for file changes. Can be specified multiple times for multiple directories.
283+
- `--access-log`, `-a`: Enable the access log.
284+
- `--debug`, `-v`: Enable verbose debug logs.
285+
- `--mercure`, `-m`: Enable the built-in Mercure.rocks hub.
286+
- `--no-compress`: Disable Zstandard, Brotli and Gzip compression.
287+
288+
### Examples
289+
290+
Start a server with the current directory as the document root:
291+
```console
292+
frankenphp php-server --root ./
293+
```
294+
295+
Start a server with HTTPS enabled:
296+
```console
297+
frankenphp php-server --domain example.com
298+
```
299+
300+
Start a server with a worker:
301+
```console
302+
frankenphp php-server --worker public/index.php
303+
```
304+
268305
## Enable the Debug Mode
269306

270307
When using the Docker image, set the `CADDY_GLOBAL_OPTIONS` environment variable to `debug` to enable the debug mode:

docs/embed.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ composer dump-env prod
4747
To customize [the configuration](config.md), you can put a `Caddyfile` as well as a `php.ini` file
4848
in the main directory of the app to be embedded (`$TMPDIR/my-prepared-app` in the previous example).
4949

50+
If an app with a Caddyfile in the directory is embedded, it will use that Caddyfile's configuration automatically when running the binary.
51+
5052
## Creating a Linux Binary
5153

5254
The easiest way to create a Linux binary is to use the Docker-based builder we provide.
@@ -106,6 +108,12 @@ To start the web app run:
106108
./my-app php-server
107109
```
108110

111+
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:
112+
113+
```console
114+
./my-app php-server --root ./
115+
```
116+
109117
If your app contains a [worker script](worker.md), start the worker with something like:
110118

111119
```console

docs/fr/config.md

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ Les directives `php_server` et `php` disposent des options suivantes :
148148

149149
```caddyfile
150150
php_server [<matcher>] {
151-
root <directory> # Définit le dossier racine du le site. Par défaut : valeur de la directive `root` parente.
151+
root <directory> # Définit le dossier racine du le site. Par défaut : valeur de la directive `root` parente. Si non spécifié, il utilisera le répertoire current_working_dir/public par défaut.
152152
split_path <delim...> # Définit les sous-chaînes pour diviser l'URI en deux parties. La première sous-chaîne correspondante sera utilisée pour séparer le "path info" du chemin. La première partie est suffixée avec la sous-chaîne correspondante et sera considérée comme le nom réel de la ressource (script CGI). La seconde partie sera définie comme PATH_INFO pour utilisation par le script. Par défaut : `.php`
153153
resolve_root_symlink false # Désactive la résolution du répertoire `root` vers sa valeur réelle en évaluant un lien symbolique, s'il existe (activé par défaut).
154154
env <key> <value> # Définit une variable d'environnement supplémentaire avec la valeur donnée. Peut être spécifié plusieurs fois pour plusieurs variables d'environnement.
@@ -264,6 +264,43 @@ Vous pouvez également modifier la configuration de PHP en utilisant la directiv
264264
}
265265
```
266266

267+
## La commande php-server
268+
269+
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).
270+
271+
```console
272+
frankenphp php-server [--domain <example.com>] [--root <path>] [--listen <addr>] [--worker /path/to/worker.php<,nb-workers>] [--watch <paths...>] [--access-log] [--debug] [--no-compress] [--mercure]
273+
```
274+
275+
### Options
276+
277+
- `--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.
278+
- `--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.
279+
- `--listen`, `-l` : L'adresse à laquelle lier l'écouteur. Par défaut, c'est `:80` ou `:443` si un domaine est spécifié.
280+
- `--worker`, `-w` : Script worker à exécuter. Peut être spécifié plusieurs fois pour plusieurs workers.
281+
- `--watch` : Répertoire à surveiller pour les changements de fichiers. Peut être spécifié plusieurs fois pour plusieurs répertoires.
282+
- `--access-log`, `-a` : Activer le journal d'accès.
283+
- `--debug`, `-v` : Activer les journaux de débogage détaillés.
284+
- `--mercure`, `-m` : Activer le hub Mercure.rocks intégré.
285+
- `--no-compress` : Désactiver la compression Zstandard, Brotli et Gzip.
286+
287+
### Exemples
288+
289+
Démarrer un serveur avec le répertoire courant comme racine de document :
290+
```console
291+
frankenphp php-server --root ./
292+
```
293+
294+
Démarrer un serveur avec HTTPS activé :
295+
```console
296+
frankenphp php-server --domain example.com
297+
```
298+
299+
Démarrer un serveur avec un worker :
300+
```console
301+
frankenphp php-server --worker public/index.php
302+
```
303+
267304
## Activer le mode debug
268305

269306
Lors de l'utilisation de l'image Docker, définissez la variable d'environnement `CADDY_GLOBAL_OPTIONS` sur `debug` pour activer le mode debug :

docs/fr/embed.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ Pour personnaliser [la configuration](config.md),
4848
vous pouvez mettre un fichier `Caddyfile` ainsi qu'un fichier `php.ini`
4949
dans le répertoire principal de l'application à intégrer
5050
(`$TMPDIR/my-prepared-app` dans l'exemple précédent).
51+
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.
5152

5253
## Créer un binaire Linux
5354

@@ -108,6 +109,12 @@ Pour démarrer l'application web, exécutez :
108109
./my-app php-server
109110
```
110111

112+
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 :
113+
114+
```console
115+
./my-app php-server --root ./
116+
```
117+
111118
Si votre application contient un [script worker](worker.md), démarrez le worker avec quelque chose comme :
112119

113120
```console

docs/ru/config.md

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ route {
141141

142142
```caddyfile
143143
php_server [<matcher>] {
144-
root <directory> # Указывает корневую директорию сайта. По умолчанию: директива `root`.
144+
root <directory> # Указывает корневую директорию сайта. По умолчанию: директива `root`. Если не указано, по умолчанию будет использоваться директория current_working_dir/public.
145145
split_path <delim...> # Устанавливает подстроки для разделения URI на две части. Первая часть будет использована как имя ресурса (CGI-скрипта), вторая часть — как PATH_INFO. По умолчанию: `.php`.
146146
resolve_root_symlink false # Отключает разрешение символьных ссылок для `root` (включено по умолчанию).
147147
env <key> <value> # Устанавливает дополнительные переменные окружения. Можно указать несколько раз для разных переменных.
@@ -234,6 +234,43 @@ CADDY_GLOBAL_OPTIONS="servers {
234234
Для загрузки [дополнительных конфигурационных файлов PHP](https://www.php.net/manual/en/configuration.file.php#configuration.file.scan) можно использовать переменную окружения `PHP_INI_SCAN_DIR`.
235235
Если она установлена, PHP загрузит все файлы с расширением `.ini`, находящиеся в указанных директориях.
236236

237+
## Команда php-server
238+
239+
Команда `php-server` — это удобный способ запустить готовый к продакшну PHP-сервер. Она особенно полезна для быстрого развертывания, демонстраций, разработки или запуска [встроенного приложения](embed.md).
240+
241+
```console
242+
frankenphp php-server [--domain <example.com>] [--root <path>] [--listen <addr>] [--worker /path/to/worker.php<,nb-workers>] [--watch <paths...>] [--access-log] [--debug] [--no-compress] [--mercure]
243+
```
244+
245+
### Опции
246+
247+
- `--domain`, `-d`: Доменное имя, на котором будут обслуживаться файлы. Если указано, сервер будет использовать HTTPS и автоматически получит сертификат Let's Encrypt.
248+
- `--root`, `-r`: Путь к корневой директории сайта. Если не указано и используется встроенное приложение, по умолчанию будет использоваться директория embedded_app/public.
249+
- `--listen`, `-l`: Адрес, к которому будет привязан слушатель. По умолчанию `:80` или `:443`, если указан домен.
250+
- `--worker`, `-w`: Скрипт worker для запуска. Может быть указан несколько раз для нескольких workers.
251+
- `--watch`: Директория для отслеживания изменений файлов. Может быть указана несколько раз для нескольких директорий.
252+
- `--access-log`, `-a`: Включить журнал доступа.
253+
- `--debug`, `-v`: Включить подробные журналы отладки.
254+
- `--mercure`, `-m`: Включить встроенный хаб Mercure.rocks.
255+
- `--no-compress`: Отключить сжатие Zstandard, Brotli и Gzip.
256+
257+
### Примеры
258+
259+
Запуск сервера с текущей директорией в качестве корневой:
260+
```console
261+
frankenphp php-server --root ./
262+
```
263+
264+
Запуск сервера с включенным HTTPS:
265+
```console
266+
frankenphp php-server --domain example.com
267+
```
268+
269+
Запуск сервера с worker:
270+
```console
271+
frankenphp php-server --worker public/index.php
272+
```
273+
237274
## Включение режима отладки
238275

239276
При использовании Docker-образа установите переменную окружения `CADDY_GLOBAL_OPTIONS` в `debug`, чтобы включить режим отладки:

docs/ru/embed.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ composer dump-env prod
4444
### Настройка конфигурации
4545

4646
Чтобы настроить [конфигурацию](config.md), вы можете разместить файлы `Caddyfile` и `php.ini` в основной директории приложения (`$TMPDIR/my-prepared-app` в примере выше).
47+
Если приложение с файлом Caddyfile в директории встроено, оно будет автоматически использовать конфигурацию из этого Caddyfile при запуске бинарного файла.
4748

4849
## Создание бинарного файла для Linux
4950

@@ -104,6 +105,12 @@ EMBED=/path/to/your/app ./build-static.sh
104105
./my-app php-server
105106
```
106107

108+
По умолчанию, если опция root не указана, будет использоваться директория embedded_app/public в качестве корневой. Если вы хотите обслуживать файлы непосредственно из директории встроенного приложения, укажите опцию root:
109+
110+
```console
111+
./my-app php-server --root ./
112+
```
113+
107114
Если ваше приложение содержит [worker-скрипт](worker.md), запустите его следующим образом:
108115

109116
```console

0 commit comments

Comments
 (0)