Skip to content
Closed
29 changes: 24 additions & 5 deletions docs/cn/compile.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,29 +61,47 @@ 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
--with github.com/dunglas/vulcain/caddy \
--with github.com/dunglas/caddy-cbrotli
# Add extra Caddy modules here
```

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 文件。
22 changes: 15 additions & 7 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,14 +98,15 @@ 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
# Add extra Caddy modules and FrankenPHP extensions here
Comment thread
henderkes marked this conversation as resolved.
--with github.com/dunglas/vulcain/caddy \
--with github.com/dunglas/caddy-cbrotli
# Add extra Caddy modules here
```

> [!TIP]
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.
Comment thread
henderkes marked this conversation as resolved.
Outdated

### 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
```
23 changes: 14 additions & 9 deletions docs/fr/compile.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,20 +91,20 @@ 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
# Ajoutez les modules Caddy supplémentaires et les extensions FrankenPHP ici
--with github.com/dunglas/vulcain/caddy \
--with github.com/dunglas/caddy-cbrotli
# Ajoutez les modules Caddy supplémentaires ici
```

> [!TIP]
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
```
18 changes: 13 additions & 5 deletions docs/ru/compile.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,24 +77,31 @@ 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
--with github.com/dunglas/vulcain/caddy \
--with github.com/dunglas/caddy-cbrotli
# Добавьте дополнительные модули Caddy здесь
```

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.
29 changes: 24 additions & 5 deletions docs/tr/compile.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,29 +63,47 @@ 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
--with github.com/dunglas/vulcain/caddy \
--with github.com/dunglas/caddy-cbrotli
# Add extra Caddy modules here
```

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
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be install-depdendencies.sh for consistency with other scripts.

Also, is bash really necessary? Alpine doesn't have Bash by default.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, bash is necessary for the way the script is written. I could rework it to work with posix shell, if you want, but I chose bash because build-static and build-packages also use 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