diff --git a/docs/cn/compile.md b/docs/cn/compile.md index cd25b0cf72..a9f01fac10 100644 --- a/docs/cn/compile.md +++ b/docs/cn/compile.md @@ -61,30 +61,48 @@ make -j"$(getconf _NPROCESSORS_ONLN)" sudo make install ``` +## 安装可选依赖项 + +FrankenPHP 的某些功能需要安装可选依赖项。 +这些功能也可以通过向 Go 编译器传递编译标签来禁用。 + +| 功能 | 依赖项 | 禁用的编译标签 | +| ----------------------------------------------------- | ------------------------------------------------------------------- | -------------- | +| Brotli 压缩 | [Brotli](https://github.com/google/brotli) | nobrotli | +| 文件更改时重启工作进程 | [Watcher C](https://github.com/e-dant/watcher/tree/release/watcher-c) | nowatcher | + ## 编译 Go 应用 您现在可以使用 Go 库并编译我们的 Caddy 构建: ```console curl -L https://github.com/dunglas/frankenphp/archive/refs/heads/main.tar.gz | tar xz -cd frankenphp-main/caddy/frankenphp -CGO_CFLAGS=$(php-config --includes) CGO_LDFLAGS="$(php-config --ldflags) $(php-config --libs)" go build +cd frankenphp-main +./install-dependencies.sh +cd caddy/frankenphp +CGO_CFLAGS="$(php-config --includes) -I$PWD/../../dist/dependencies/include" \ +CGO_LDFLAGS="$(php-config --ldflags) $(php-config --libs) -L$PWD/../../dist/dependencies/lib" \ +go build -tags=nobadger,nomysql,nopgx ``` +请注意,这将生成一个没有 Mercure 或 Vulcain 的 `frankenphp` 二进制文件。对于生产用途,最好使用 xcaddy。 + ### 使用 xcaddy 你可以使用 [xcaddy](https://github.com/caddyserver/xcaddy) 来编译 [自定义 Caddy 模块](https://caddyserver.com/docs/modules/) 的 FrankenPHP: ```console CGO_ENABLED=1 \ -XCADDY_GO_BUILD_FLAGS="-ldflags '-w -s'" \ +XCADDY_GO_BUILD_FLAGS="-ldflags='-w -s' -tags=nobadger,nomysql,nopgx" \ +CGO_CFLAGS="$(php-config --includes) -I$PWD/../../dist/dependencies/include" \ +CGO_LDFLAGS="$(php-config --ldflags) $(php-config --libs) -L$PWD/../../dist/dependencies/lib" \ xcaddy build \ --output frankenphp \ --with github.com/dunglas/frankenphp/caddy \ - --with github.com/dunglas/caddy-cbrotli \ --with github.com/dunglas/mercure/caddy \ - --with github.com/dunglas/vulcain/caddy - # Add extra Caddy modules here + --with github.com/dunglas/vulcain/caddy \ + --with github.com/dunglas/caddy-cbrotli + # 在此处添加额外的 Caddy 模块和 FrankenPHP 扩展 ``` > [!TIP] @@ -96,3 +114,4 @@ xcaddy build \ > 请将 `XCADDY_GO_BUILD_FLAGS` 环境变量更改为如下类似的值 > `XCADDY_GO_BUILD_FLAGS=$'-ldflags "-w -s -extldflags \'-Wl,-z,stack-size=0x80000\'"'` > (根据您的应用需求更改堆栈大小)。 +> 有关更多信息,请查看 build-static.sh 文件。 diff --git a/docs/compile.md b/docs/compile.md index e2c4af8262..83fe524bfe 100644 --- a/docs/compile.md +++ b/docs/compile.md @@ -79,6 +79,8 @@ sudo make install Some FrankenPHP features depend on optional system dependencies that must be installed. Alternatively, these features can be disabled by passing build tags to the Go compiler. +To install them, run ./install-dependencies.sh in the FrankenPHP source directory. + | Feature | Dependency | Build tag to disable it | |--------------------------------|-----------------------------------------------------------------------|-------------------------| | Brotli compression | [Brotli](https://github.com/google/brotli) | nobrotli | @@ -86,7 +88,7 @@ Alternatively, these features can be disabled by passing build tags to the Go co ## Compile the Go App -You can now build the final binary. +You can now build the binary. ### Using xcaddy @@ -96,13 +98,14 @@ The recommended way is to use [xcaddy](https://github.com/caddyserver/xcaddy) to ```console CGO_ENABLED=1 \ XCADDY_GO_BUILD_FLAGS="-ldflags='-w -s' -tags=nobadger,nomysql,nopgx" \ -CGO_CFLAGS=$(php-config --includes) \ -CGO_LDFLAGS="$(php-config --ldflags) $(php-config --libs)" \ +CGO_CFLAGS="$(php-config --includes) -I$PWD/../../dist/dependencies/include" \ +CGO_LDFLAGS="$(php-config --ldflags) $(php-config --libs) -L$PWD/../../dist/dependencies/lib" \ xcaddy build \ --output frankenphp \ --with github.com/dunglas/frankenphp/caddy \ --with github.com/dunglas/mercure/caddy \ - --with github.com/dunglas/vulcain/caddy + --with github.com/dunglas/vulcain/caddy \ + --with github.com/dunglas/caddy-cbrotli # Add extra Caddy modules and FrankenPHP extensions here ``` @@ -115,6 +118,7 @@ xcaddy build \ > To do so, change the `XCADDY_GO_BUILD_FLAGS` environment variable to something like > `XCADDY_GO_BUILD_FLAGS=$'-ldflags "-w -s -extldflags \'-Wl,-z,stack-size=0x80000\'"'` > (change the stack size value according to your app needs). +> Check the `build-static.sh` file for more information. ### Without xcaddy @@ -122,6 +126,10 @@ Alternatively, it's possible to compile FrankenPHP without `xcaddy` by using the ```console curl -L https://github.com/dunglas/frankenphp/archive/refs/heads/main.tar.gz | tar xz -cd frankenphp-main/caddy/frankenphp -CGO_CFLAGS=$(php-config --includes) CGO_LDFLAGS="$(php-config --ldflags) $(php-config --libs)" go build -tags=nobadger,nomysql,nopgx +cd frankenphp-main +./install-dependencies.sh +cd caddy/frankenphp +CGO_CFLAGS="$(php-config --includes) -I$PWD/../../dist/dependencies/include" \ +CGO_LDFLAGS="$(php-config --ldflags) $(php-config --libs) -L$PWD/../../dist/dependencies/lib" \ +go build -tags=nobadger,nomysql,nopgx ``` diff --git a/docs/fr/compile.md b/docs/fr/compile.md index e7f7bd7bcf..992ea6a9fc 100644 --- a/docs/fr/compile.md +++ b/docs/fr/compile.md @@ -91,19 +91,19 @@ Ces fonctionnalités peuvent également être désactivées en passant des tags ### Utiliser xcaddy La méthode recommandée consiste à utiliser [xcaddy](https://github.com/caddyserver/xcaddy) pour compiler FrankenPHP. -`xcaddy` permet également d'ajouter facilement des [modules Caddy personnalisés](https://caddyserver.com/docs/modules/) et des extensions FrankenPHP : +`xcaddy` permet également d'ajouter facilement des [modules Caddy personnalisés](https://caddyserver.com/docs/modules/) : ```console CGO_ENABLED=1 \ XCADDY_GO_BUILD_FLAGS="-ldflags='-w -s' -tags=nobadger,nomysql,nopgx" \ -CGO_CFLAGS=$(php-config --includes) \ -CGO_LDFLAGS="$(php-config --ldflags) $(php-config --libs)" \ +CGO_CFLAGS="$(php-config --includes) -I$PWD/../../dist/dependencies/include" \ +CGO_LDFLAGS="$(php-config --ldflags) $(php-config --libs) -L$PWD/../../dist/dependencies/lib" \ xcaddy build \ --output frankenphp \ --with github.com/dunglas/frankenphp/caddy \ - --with github.com/dunglas/caddy-cbrotli \ --with github.com/dunglas/mercure/caddy \ - --with github.com/dunglas/vulcain/caddy + --with github.com/dunglas/vulcain/caddy \ + --with github.com/dunglas/caddy-cbrotli # Ajoutez les modules Caddy supplémentaires et les extensions FrankenPHP ici ``` @@ -116,13 +116,18 @@ xcaddy build \ > Pour ce faire, modifiez la variable d'environnement `XCADDY_GO_BUILD_FLAGS` en quelque chose comme > `XCADDY_GO_BUILD_FLAGS=$'-ldflags "-w -s -extldflags \'-Wl,-z,stack-size=0x80000\'"'` > (modifiez la valeur de la taille de la pile selon les besoins de votre application). +> Consultez le fichier build-static.sh pour plus d’informations. ### Sans xcaddy -Il est également possible de compiler FrankenPHP sans `xcaddy` en utilisant directement la commande `go` : +Il est également possible de compiler FrankenPHP sans xcaddy en utilisant directement la commande go : ```console curl -L https://github.com/dunglas/frankenphp/archive/refs/heads/main.tar.gz | tar xz -cd frankenphp-main/caddy/frankenphp -CGO_CFLAGS=$(php-config --includes) CGO_LDFLAGS="$(php-config --ldflags) $(php-config --libs)" go build -tags=nobadger,nomysql,nopgx +cd frankenphp-main +./install-dependencies.sh +cd caddy/frankenphp +CGO_CFLAGS="$(php-config --includes) -I$PWD/../../dist/dependencies/include" \ +CGO_LDFLAGS="$(php-config --ldflags) $(php-config --libs) -L$PWD/../../dist/dependencies/lib" \ +go build -tags=nobadger,nomysql,nopgx ``` diff --git a/docs/mercure.md b/docs/mercure.md index 223a6c8ea9..34ce3b399e 100644 --- a/docs/mercure.md +++ b/docs/mercure.md @@ -9,7 +9,7 @@ No JS library or SDK is required! To enable the Mercure hub, update the `Caddyfile` as described [on Mercure's site](https://mercure.rocks/docs/hub/config). -The path of the Mercure hub is `/.well-known/mercure`. +The path of the Mercure hub is `/.well-known/mercure`. When running FrankenPHP inside Docker, the full send URL would look like `http://php/.well-known/mercure` (with `php` being the container's name running FrankenPHP). To push Mercure updates from your code, we recommend the [Symfony Mercure Component](https://symfony.com/components/Mercure) (you don't need the Symfony full-stack framework to use it). diff --git a/docs/ru/compile.md b/docs/ru/compile.md index e547be21ab..c0e38b7475 100644 --- a/docs/ru/compile.md +++ b/docs/ru/compile.md @@ -77,10 +77,16 @@ sudo make install ```console curl -L https://github.com/dunglas/frankenphp/archive/refs/heads/main.tar.gz | tar xz -cd frankenphp-main/caddy/frankenphp -CGO_CFLAGS=$(php-config --includes) CGO_LDFLAGS="$(php-config --ldflags) $(php-config --libs)" go build -tags=nobadger,nomysql,nopgx +cd frankenphp-main +./install-dependencies.sh +cd caddy/frankenphp +CGO_CFLAGS="$(php-config --includes) -I$PWD/../../dist/dependencies/include" \ +CGO_LDFLAGS="$(php-config --ldflags) $(php-config --libs) -L$PWD/../../dist/dependencies/lib" \ +go build -tags=nobadger,nomysql,nopgx ``` +Обратите внимание, что это создаст бинарный файл `frankenphp` без Mercure и Vulcain. Для производственного использования лучше использовать xcaddy. + ### Использование xcaddy Альтернативно, используйте [xcaddy](https://github.com/caddyserver/xcaddy) для компиляции FrankenPHP с [пользовательскими модулями Caddy](https://caddyserver.com/docs/modules/): @@ -88,14 +94,15 @@ CGO_CFLAGS=$(php-config --includes) CGO_LDFLAGS="$(php-config --ldflags) $(php-c ```console CGO_ENABLED=1 \ XCADDY_GO_BUILD_FLAGS="-ldflags='-w -s' -tags=nobadger,nomysql,nopgx" \ -CGO_CFLAGS=$(php-config --includes) \ -CGO_LDFLAGS="$(php-config --ldflags) $(php-config --libs)" \ +CGO_CFLAGS="$(php-config --includes) -I$PWD/../../dist/dependencies/include" \ +CGO_LDFLAGS="$(php-config --ldflags) $(php-config --libs) -L$PWD/../../dist/dependencies/lib" \ xcaddy build \ --output frankenphp \ --with github.com/dunglas/frankenphp/caddy \ --with github.com/dunglas/mercure/caddy \ - --with github.com/dunglas/vulcain/caddy - # Добавьте дополнительные модули Caddy здесь + --with github.com/dunglas/vulcain/caddy \ + --with github.com/dunglas/caddy-cbrotli + # Добавьте дополнительные модули Caddy и расширения FrankenPHP здесь ``` > [!TIP] @@ -108,3 +115,4 @@ xcaddy build \ > Для этого измените значение переменной окружения `XCADDY_GO_BUILD_FLAGS`, например: > `XCADDY_GO_BUILD_FLAGS=$'-ldflags "-w -s -extldflags \'-Wl,-z,stack-size=0x80000\'"'` > (измените значение размера стека в зависимости от требований вашего приложения). +> Для получения дополнительной информации ознакомьтесь с файлом build-static.sh. diff --git a/docs/tr/compile.md b/docs/tr/compile.md index ceae3ef068..6b5bfd198b 100644 --- a/docs/tr/compile.md +++ b/docs/tr/compile.md @@ -63,30 +63,48 @@ make -j"$(getconf _NPROCESSORS_ONLN)" sudo make install ``` +## İsteğe Bağlı Bağımlılıkları Yükleyin + +FrankenPHP'nin bazı özellikleri, yüklenmesi gereken isteğe bağlı bağımlılıklara ihtiyaç duyar. +Bu özellikler, Go derleyicisine derleme etiketleri geçirilerek de devre dışı bırakılabilir. + +| Özellik | Bağımlılık | Devre dışı bırakmak için derleme etiketi | +| ------------------------------------------------------ | -------------------------------------------------------------------- | ---------------------------------------- | +| Brotli sıkıştırma | [Brotli](https://github.com/google/brotli) | nobrotli | +| Dosya değişikliğinde işçileri yeniden başlatma | [Watcher C](https://github.com/e-dant/watcher/tree/release/watcher-c) | nowatcher | + ## Go Uygulamasını Derleyin Artık Go kütüphanesini kullanabilir ve Caddy yapımızı derleyebilirsiniz: ```console curl -L https://github.com/dunglas/frankenphp/archive/refs/heads/main.tar.gz | tar xz -cd frankenphp-main/caddy/frankenphp -CGO_CFLAGS=$(php-config --includes) CGO_LDFLAGS="$(php-config --ldflags) $(php-config --libs)" go build +cd frankenphp-main +./install-dependencies.sh +cd caddy/frankenphp +CGO_CFLAGS="$(php-config --includes) -I$PWD/../../dist/dependencies/include" \ +CGO_LDFLAGS="$(php-config --ldflags) $(php-config --libs) -L$PWD/../../dist/dependencies/lib" \ +go build -tags=nobadger,nomysql,nopgx ``` +Bu, Mercure veya Vulcain olmadan bir `frankenphp` ikili dosyası oluşturacaktır. Üretim kullanımı için xcaddy kullanmak daha iyidir. + ### Xcaddy kullanımı Alternatif olarak, FrankenPHP'yi [özel Caddy modülleri](https://caddyserver.com/docs/modules/) ile derlemek için [xcaddy](https://github.com/caddyserver/xcaddy) kullanın: ```console CGO_ENABLED=1 \ -XCADDY_GO_BUILD_FLAGS="-ldflags '-w -s'" \ +XCADDY_GO_BUILD_FLAGS="-ldflags='-w -s' -tags=nobadger,nomysql,nopgx" \ +CGO_CFLAGS="$(php-config --includes) -I$PWD/../../dist/dependencies/include" \ +CGO_LDFLAGS="$(php-config --ldflags) $(php-config --libs) -L$PWD/../../dist/dependencies/lib" \ xcaddy build \ --output frankenphp \ --with github.com/dunglas/frankenphp/caddy \ - --with github.com/dunglas/caddy-cbrotli \ --with github.com/dunglas/mercure/caddy \ - --with github.com/dunglas/vulcain/caddy - # Add extra Caddy modules here + --with github.com/dunglas/vulcain/caddy \ + --with github.com/dunglas/caddy-cbrotli + # Ekstra Caddy modüllerini ve FrankenPHP uzantılarını buraya ekleyin ``` > [!TIP] @@ -98,3 +116,4 @@ xcaddy build \ > Bunu yapmak için, `XCADDY_GO_BUILD_FLAGS` ortam değişkenini bu şekilde değiştirin > `XCADDY_GO_BUILD_FLAGS=$'-ldflags "-w -s -extldflags \'-Wl,-z,stack-size=0x80000\'"'` > (yığın boyutunun değerini uygulamanızın ihtiyaçlarına göre değiştirin). +> Daha fazla bilgi için build-static.sh dosyasını kontrol edin. diff --git a/install-dependencies.sh b/install-dependencies.sh new file mode 100755 index 0000000000..044be4925d --- /dev/null +++ b/install-dependencies.sh @@ -0,0 +1,78 @@ +#!/bin/bash +set -euo pipefail + +# Set paths +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +DIST_DIR="${SCRIPT_DIR}/dist/dependencies" +BUILDROOT_LIB="$DIST_DIR/lib" +BUILDROOT_INCLUDE="$DIST_DIR/include" + +# Ensure folders exist +mkdir -p "$BUILDROOT_LIB" "$BUILDROOT_INCLUDE" + +# Check for libwatcher-c.a and header +if [ ! -f "$BUILDROOT_LIB/libwatcher-c.a" ] || [ ! -f "$BUILDROOT_INCLUDE/wtr/watcher-c.h" ]; then + echo "Building libwatcher-c..." + mkdir -p watcher + cd watcher + curl -sL https://api.github.com/repos/e-dant/watcher/releases/latest | + grep tarball_url | + awk -F '"' '{print $4}' | + xargs curl -sL | tar xz --strip-components=1 + cd watcher-c + ${CC:-cc} -c -o libwatcher-c.o ./src/watcher-c.cpp -I ./include -I ../include -std=c++17 -Wall -Wextra -fPIC + ar rcs libwatcher-c.a libwatcher-c.o + cp libwatcher-c.a "$BUILDROOT_LIB/" + mkdir -p "$BUILDROOT_INCLUDE/wtr" + cp -R include/wtr/watcher-c.h "$BUILDROOT_INCLUDE/wtr/" + cd ../../ + rm -rf watcher +fi + +# Check for Brotli static libs and headers +if [ ! -f "$BUILDROOT_LIB/libbrotlienc.a" ] || + [ ! -f "$BUILDROOT_LIB/libbrotlidec.a" ] || + [ ! -f "$BUILDROOT_LIB/libbrotlicommon.a" ] || + [ ! -d "$BUILDROOT_INCLUDE/brotli" ]; then + echo "Building Brotli..." + if ! command -v cmake &>/dev/null; then + echo "cmake is not installed. Please install cmake to build Brotli." + exit 1 + fi + git clone --depth 1 https://github.com/google/brotli.git brotli-source + cd brotli-source + mkdir out && cd out + cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DBUILD_SHARED_LIBS=OFF .. + make -j"$(nproc)" + cp libbrotlienc.a libbrotlidec.a libbrotlicommon.a "$BUILDROOT_LIB/" + cp -R ../c/include/brotli "$BUILDROOT_INCLUDE/" + cd ../../ + rm -rf brotli-source +fi + +if ! command -v xcaddy &>/dev/null; then + echo "Installing xcaddy..." + + go install github.com/caddyserver/xcaddy/cmd/xcaddy@latest + + # Determine install path + if [ -n "${GOBIN:-}" ] && [ -x "$GOBIN/xcaddy" ]; then + XCADDY="$GOBIN/xcaddy" + elif [ -n "${GOPATH:-}" ] && [ -x "$GOPATH/bin/xcaddy" ]; then + XCADDY="$GOPATH/bin/xcaddy" + elif [ -x "$HOME/go/bin/xcaddy" ]; then + XCADDY="$HOME/go/bin/xcaddy" + else + echo "Error: xcaddy installed but not found in expected paths." >&2 + echo "Ensure \$GOBIN, \$GOPATH/bin, or \$HOME/go/bin exists and contains xcaddy." >&2 + exit 1 + fi + + echo "xcaddy installed at: $XCADDY" + EXPORT_CMD="export PATH=\"$(dirname "$XCADDY"):\$PATH\"" + + echo "To make xcaddy available, run the following:" + echo " echo '$EXPORT_CMD' >> ~/.bashrc && source ~/.bashrc" +else + XCADDY="$(command -v xcaddy)" +fi