Contributing

Compiling PHP

With Docker (Linux)

Build the dev Docker image:

  1. docker build -t frankenphp-dev -f dev.Dockerfile .
  2. docker run --cap-add=SYS_PTRACE --security-opt seccomp=unconfined -p 8080:8080 -p 443:443 -p 443:443/udp -v $PWD:/go/src/app -it frankenphp-dev

The image contains the usual development tools (Go, GDB, Valgrind, Neovim…).

If docker version is lower than 23.0, build is failed by dockerignore pattern issue. Add directories to .dockerignore.

  1. !testdata/*.php
  2. !testdata/*.txt
  3. +!caddy
  4. +!internal

Without Docker (Linux and macOS)

Follow the instructions to compile from sources and pass the --debug configuration flag.

Running the test suite

  1. go test -tags watcher -race -v ./...

Caddy module

Build Caddy with the FrankenPHP Caddy module:

  1. cd caddy/frankenphp/
  2. go build -tags watcher,brotli,nobadger,nomysql,nopgx
  3. cd ../../

Run the Caddy with the FrankenPHP Caddy module:

  1. cd testdata/
  2. ../caddy/frankenphp/frankenphp run

The server is listening on 127.0.0.1:8080:

  1. curl -vk https://localhost/phpinfo.php

Minimal test server

Build the minimal test server:

  1. cd internal/testserver/
  2. go build
  3. cd ../../

Run the test server:

  1. cd testdata/
  2. ../internal/testserver/testserver

The server is listening on 127.0.0.1:8080:

  1. curl -v http://127.0.0.1:8080/phpinfo.php

Building Docker Images Locally

Print bake plan:

  1. docker buildx bake -f docker-bake.hcl --print

Build FrankenPHP images for amd64 locally:

  1. docker buildx bake -f docker-bake.hcl --pull --load --set "*.platform=linux/amd64"

Build FrankenPHP images for arm64 locally:

  1. docker buildx bake -f docker-bake.hcl --pull --load --set "*.platform=linux/arm64"

Build FrankenPHP images from scratch for arm64 & amd64 and push to Docker Hub:

  1. docker buildx bake -f docker-bake.hcl --pull --no-cache --push

Debugging Segmentation Faults With Static Builds

  1. Download the debug version of the FrankenPHP binary from GitHub or create your custom static build including debug symbols:

    1. docker buildx bake \
    2. --load \
    3. --set static-builder.args.DEBUG_SYMBOLS=1 \
    4. --set "static-builder.platform=linux/amd64" \
    5. static-builder
    6. docker cp $(docker create --name static-builder dunglas/frankenphp:static-builder):/go/src/app/dist/frankenphp-linux-$(uname -m) frankenphp
  2. Replace your current version of frankenphp by the debug FrankenPHP executable

  3. Start FrankenPHP as usual (alternatively, you can directly start FrankenPHP with GDB: gdb --args frankenphp run)

  4. Attach to the process with GDB:

    1. gdb -p `pidof frankenphp`
  5. If necessary, type continue in the GDB shell

  6. Make FrankenPHP crash

  7. Type bt in the GDB shell

  8. Copy the output

Debugging Segmentation Faults in GitHub Actions

  1. Open .github/workflows/tests.yml

  2. Enable PHP debug symbols

    1. - uses: shivammathur/setup-php@v2
    2. # ...
    3. env:
    4. phpts: ts
    5. + debug: true
  3. Enable tmate to connect to the container

    1. -
    2. name: Set CGO flags
    3. run: echo "CGO_CFLAGS=$(php-config --includes)" >> "$GITHUB_ENV"
    4. + -
    5. + run: |
    6. + sudo apt install gdb
    7. + mkdir -p /home/runner/.config/gdb/
    8. + printf "set auto-load safe-path /\nhandle SIG34 nostop noprint pass" > /home/runner/.config/gdb/gdbinit
    9. + -
    10. + uses: mxschmitt/action-tmate@v3
  4. Connect to the container

  5. Open frankenphp.go

  6. Enable cgosymbolizer

    1. - //_ "github.com/ianlancetaylor/cgosymbolizer"
    2. + _ "github.com/ianlancetaylor/cgosymbolizer"
  7. Download the module: go get

  8. In the container, you can use GDB and the like:

    1. go test -tags watcher -c -ldflags=-w
    2. gdb --args frankenphp.test -test.run ^MyTest$
  9. When the bug is fixed, revert all these changes

Misc Dev Resources

Useful Command

  1. apk add strace util-linux gdb
  2. strace -e 'trace=!futex,epoll_ctl,epoll_pwait,tgkill,rt_sigreturn' -p 1

Translating the Documentation

To translate the documentation and the site in a new language, follow these steps:

  1. Create a new directory named with the language’s 2-character ISO code in this repository’s docs/ directory
  2. Copy all the .md files in the root of the docs/ directory into the new directory (always use the English version as source for translation, as it’s always up to date)
  3. Copy the README.md and CONTRIBUTING.md files from the root directory to the new directory
  4. Translate the content of the files, but don’t change the filenames, also don’t translate strings starting with > [! (it’s special markup for GitHub)
  5. Create a Pull Request with the translations
  6. In the site repository, copy and translate the translation files in the content/, data/ and i18n/ directories
  7. Translate the values in the created YAML file
  8. Open a Pull Request on the site repository