Files
frankenphp/docs/cn/config.md
Marc bbbfdb31b5 ci: build .rpm and .deb packages (#1497)
* add ./create-rpm.sh file to build a "frankenphp" rpm package

* also build a deb package

* renamed to build-packages

* linter...

* add depends

* linter again?

* linter number 3

* linter number 4

* set default locations for ini file, conf files and extensions

* set unified path for modules that should be ok on all dists

* add default content into "package" folder

* make file executable

* worker is in public folder

* what on earth did I do x)

* use same FRANKENPHP_VERSION and make sure to let pr's run the rpm generation too (version 0.0.0) to see issues

* install ruby, fpm and rpm-build

* move to after changing base urls because it would fail with packages not found

* ruby 3 build needs gcc 10

* rpm-build is necessary too...

* and I forgot to link the package folder

* create directories if they don't exist

* copy out all frankenphp* files?

* lint fix

* only copy frankenphp-* files

* only copy frankenphp-* files

* the .deb file is name frankenphp_1.5.0... - create output folder instead and upload all things inside that
will simplify things when later adding xdebug.so and ffi.so

* update the last two steps to use the gh-output directory

* add post install script to set frankenphp able to bind to port 80 for non-root users

* dnf over yum, I think the yum alias was removed in RH 9.5

* newlines

* newlines

* add text what missing libcap means

* copy php.ini-production from php-src, linter, update ruby version

* move Caddyfile to /etc/frankenphp/Caddyfile

* linter

* fix a copy and paste error

* better describe fallback to 0.0.0

* linter

* copy installation scripts from official caddy packages, change user to frankenphp too

* bombombom

* make files executable

* tabs

* linter

* linter again

* use empty directory for three different destinations instead of keeping three empty local directories

* caddy says the file is incorrectly formatted without these spaces

* remove wildcard matcher from root directive

* Apply suggestions from code review

commit suggested changes to preinstall/postinstall scripts

Co-authored-by: Kévin Dunglas <kevin@dunglas.fr>

* Update dev.Dockerfile

Co-authored-by: Kévin Dunglas <kevin@dunglas.fr>

* remove misleading comment

* update documentation for paths

* update documentation for paths some more

* fix musl opcache-jit issue

* markdown linter

* the damn tab

* Apply suggestions from code review

Co-authored-by: Kévin Dunglas <kevin@dunglas.fr>

* drop dev.Dockerfile php location from config.md

* add php config note to CONTRIBUTING.md

* dashes instead of asterisks in chinese docs

* fix package building

* create frankenphp user in case it doesn't exist for deb packages

* create users if they don't exist, delete them again if they didn't exist

* satisfy linter

* create the user with the same commands as the postinst/preinstall scripts

* Removes toolchain requirements.

* trigger

* Removes explicit calls to go get

* trigger

* setcap by default

* simplify example project

* bring page more in line with the caddy / apache / nginx default page

* update to html 5

* oopsies

* revert style to original

* remove https:// (caddy uses http:// on RHEL, :80 on Debian)

---------

Co-authored-by: Kévin Dunglas <kevin@dunglas.fr>
Co-authored-by: Alliballibaba <alliballibaba@gmail.com>
2025-05-14 07:33:05 +02:00

5.2 KiB
Raw Blame History

配置

FrankenPHPCaddy 以及 Mercure 和 Vulcain 模块可以使用 Caddy 支持的格式 进行配置。

Docker 映像 中,Caddyfile 位于 /etc/frankenphp/Caddyfile。 静态二进制文件会在启动时所在的目录中查找 Caddyfile。 PHP 本身可以使用 php.ini 文件进行配置。 PHP 解释器将在以下位置查找:

Docker:

  • php.ini: /usr/local/etc/php/php.ini 默认情况下不提供 php.ini。
  • 附加配置文件: /usr/local/etc/php/conf.d/*.ini
  • php 扩展: /usr/local/lib/php/extensions/no-debug-zts-<YYYYMMDD>/
  • 您应该复制 PHP 项目提供的官方模板:
FROM dunglas/frankenphp

# 生产:
RUN cp $PHP_INI_DIR/php.ini-production $PHP_INI_DIR/php.ini

# 开发:
RUN cp $PHP_INI_DIR/php.ini-development $PHP_INI_DIR/php.ini

FrankenPHP 安装 (.rpm 或 .deb):

  • php.ini: /etc/frankenphp/php.ini 默认情况下提供带有生产预设的 php.ini 文件。
  • 附加配置文件: /etc/frankenphp/php.d/*.ini
  • php 扩展: /usr/lib/frankenphp/modules/

静态二进制:

  • php.ini: 执行 frankenphp runfrankenphp php-server 的目录,然后是 /etc/frankenphp/php.ini
  • 附加配置文件: /etc/frankenphp/php.d/*.ini
  • php 扩展: 无法加载
  • 复制PHP 源代码中提供的php.ini-productionphp.ini-development中的一个。

Caddyfile 配置

要注册 FrankenPHP 执行器,必须设置 frankenphp 全局选项,然后可以在站点块中使用 php_serverphp HTTP 指令 来为您的 PHP 应用程序提供服务。

最小示例:

{
	# 启用 FrankenPHP
	frankenphp
}

localhost {
	# 启用压缩(可选)
	encode zstd br gzip
	# 执行当前目录中的 PHP 文件并提供资产
	php_server
}

或者,可以在全局选项下指定要创建的线程数和要从服务器启动的 worker 脚本

{
	frankenphp {
		num_threads <num_threads> # 设置要启动的 PHP 线程数。默认值:可用 CPU 数量的 2 倍。
		worker {
			file <path> # 设置 worker 脚本的路径。
			num <num> # 设置要启动的 PHP 线程数,默认为可用 CPU 数的 2 倍。
			env <key> <value> # 将额外的环境变量设置为给定值。可以为多个环境变量多次指定。
		}
	}
}

# ...

或者,您可以使用 worker 选项的一行缩写形式:

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

# ...

如果在同一服务器上运行多个应用,还可以定义多个 worker

{
	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
	php_server
}

other.example.com {
	root /path/to/other/public
	php_server
}
# ...

通常你只需要 php_server 指令, 但如果要完全控制,则可以使用较低级别的 php 指令:

使用 php_server 指令等效于以下配置:

route {
	# 为目录请求添加尾部斜杠
	@canonicalPath {
		file {path}/index.php
		not path */
	}
	redir @canonicalPath {path}/ 308
	# 如果请求的文件不存在,则尝试 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
}

php_serverphp 指令具有以下选项:

php_server [<matcher>] {
	root <directory> # 设置站点的根目录。默认值:`root` 指令。
	split_path <delim...> # 设置用于将 URI 拆分为两部分的子字符串。第一个匹配的子字符串将用于从路径中拆分“路径信息”。第一个部分以匹配的子字符串为后缀,并将假定为实际资源(CGI 脚本)名称。第二部分将设置为PATH_INFO供脚本使用。默认值`.php`
	resolve_root_symlink false # 禁用将 `root` 目录在符号链接时将其解析为实际值(默认启用)。
	env <key> <value> # 设置额外的环境变量,可以设置多个环境变量。
}

环境变量

以下环境变量可用于在 Caddyfile 中注入 Caddy 指令,而无需对其进行修改:

  • SERVER_NAME: 更改 要监听的地址,提供的主机名也将用于生成的 TLS 证书
  • CADDY_GLOBAL_OPTIONS: 注入 全局选项
  • FRANKENPHP_CONFIG: 在 frankenphp 指令下注入配置

PHP 配置

要加载 其他 PHP INI 配置文件 可以使用 PHP_INI_SCAN_DIR 环境变量。 设置后PHP 将加载给定目录中存在 .ini 扩展名的所有文件。

启用调试模式

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

docker run -v $PWD:/app/public \
    -e CADDY_GLOBAL_OPTIONS=debug \
    -p 80:80 -p 443:443 -p 443:443/udp \
    dunglas/frankenphp