dunglas / frankenphp

🧟 The modern PHP app server
https://frankenphp.dev
MIT License
6.64k stars 218 forks source link

Can't build with xcaddy, undefined: FrankenPHPContext #699

Closed Embiggenerd closed 5 months ago

Embiggenerd commented 5 months ago

What happened?

Hello, I ran

./xcaddy build --with github.com/dunglas/frankenphp/caddy

from inside go/bin directory and received

2024/03/31 19:18:03 [INFO] exec (timeout=0s): /snap/bin/go build -o /root/go/bin/caddy -ldflags -w -s -trimpath 
^[[A^[[A^[[B^[[B# github.com/dunglas/frankenphp
/root/go/pkg/mod/github.com/dunglas/frankenphp@v1.1.2/request_options.go:10:28: undefined: FrankenPHPContext
/root/go/pkg/mod/github.com/dunglas/frankenphp@v1.1.2/request_options.go:20:17: undefined: FrankenPHPContext
/root/go/pkg/mod/github.com/dunglas/frankenphp@v1.1.2/request_options.go:48:17: undefined: FrankenPHPContext
/root/go/pkg/mod/github.com/dunglas/frankenphp@v1.1.2/request_options.go:73:17: undefined: FrankenPHPContext
/root/go/pkg/mod/github.com/dunglas/frankenphp@v1.1.2/request_options.go:82:17: undefined: FrankenPHPContext
2024/03/31 19:20:43 [INFO] Cleaning up temporary folder: /tmp/buildenv_2024-03-31-1917.3331508884
2024/03/31 19:20:43 [FATAL] exit status 1

I am also confused why there isn't a simple installation step. When I am looking for this sort of solution, I skim docs for a simple install step, and if I don't find it, I move on. I am only using this because I am already using caddy.

If you put this in the beginning of docs:

  1. How to install plugin
  2. How to configure Caddyfile to use plugin for simplest possible scenario

This will double your adoption rate.

Build Type

Custom (tell us more in the description)

Worker Mode

Yes

Operating System

GNU/Linux

CPU Architecture

x86_64

PHP configuration

Never got to this step.

Relevant log output

2024/03/31 19:18:03 [INFO] exec (timeout=0s): /snap/bin/go build -o /root/go/bin/caddy -ldflags -w -s -trimpath 
^[[A^[[A^[[B^[[B# github.com/dunglas/frankenphp
/root/go/pkg/mod/github.com/dunglas/frankenphp@v1.1.2/request_options.go:10:28: undefined: FrankenPHPContext
/root/go/pkg/mod/github.com/dunglas/frankenphp@v1.1.2/request_options.go:20:17: undefined: FrankenPHPContext
/root/go/pkg/mod/github.com/dunglas/frankenphp@v1.1.2/request_options.go:48:17: undefined: FrankenPHPContext
/root/go/pkg/mod/github.com/dunglas/frankenphp@v1.1.2/request_options.go:73:17: undefined: FrankenPHPContext
/root/go/pkg/mod/github.com/dunglas/frankenphp@v1.1.2/request_options.go:82:17: undefined: FrankenPHPContext
2024/03/31 19:20:43 [INFO] Cleaning up temporary folder: /tmp/buildenv_2024-03-31-1917.3331508884
2024/03/31 19:20:43 [FATAL] exit status 1
dunglas commented 5 months ago

You need to enable CGO. See https://frankenphp.dev/docs/compile/#using-xcaddy

Embiggenerd commented 5 months ago

running command

CGO_ENABLED=1 XCADDY_GO_BUILD_FLAGS="-ldflags '-w -s'" ./xcaddy build --output frankenphp --with github.com/dunglas/frankenphp/caddy --with github.com/dunglas/mercure/caddy --with github.com/dunglas/vulcain/caddy

resulted in this out put

In file included from /root/go/pkg/mod/github.com/dunglas/frankenphp@v1.1.2/cgi.go:3:
./frankenphp.h:4:10: fatal error: Zend/zend_types.h: No such file or directory
    4 | #include <Zend/zend_types.h>
      |          ^~~~~~~~~~~~~~~~~~~
dunglas commented 5 months ago

This means that the PHP include files aren't in the include path. Please try the tutorial linked above from the beginning.

zauni commented 1 month ago

As another option one could do a static build. But I can't see where it would be possible to add other Caddy plugins in a static build. This is only possible with the xcaddy command and the --with arguments. But then you need to have PHP dynamically linked. @dunglas Is it possible to do a static build as described in the docs, but also add other Caddy plugins?