Skip to content
Closed
31 changes: 25 additions & 6 deletions docs/cn/compile.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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 文件。
20 changes: 14 additions & 6 deletions docs/compile.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,16 @@ 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 |
| Restart workers on file change | [Watcher C](https://github.com/e-dant/watcher/tree/release/watcher-c) | nowatcher |

## Compile the Go App

You can now build the final binary.
You can now build the binary.

### Using xcaddy

Expand All @@ -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
Comment thread
henderkes marked this conversation as resolved.
```

Expand All @@ -115,13 +118,18 @@ 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

Alternatively, it's possible to compile FrankenPHP without `xcaddy` by using the `go` command directly:

```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
```
21 changes: 13 additions & 8 deletions docs/fr/compile.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

Expand All @@ -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
```
2 changes: 1 addition & 1 deletion docs/mercure.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
20 changes: 14 additions & 6 deletions docs/ru/compile.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,25 +77,32 @@ 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/):

```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]
Expand All @@ -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.
31 changes: 25 additions & 6 deletions docs/tr/compile.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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.
78 changes: 78 additions & 0 deletions install-dependencies.sh
Original file line number Diff line number Diff line change
@@ -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
Loading