frankenphp icon indicating copy to clipboard operation
frankenphp copied to clipboard

Static Build with Symfony Application - 404 for all routes

Open tina-junold opened this issue 11 months ago • 4 comments

Hi,

I think it must be a configuration issue but i don't see the reason. I've created a Symfony Application to test it with FrankenPHP. While it's working with the pre-build docker container, the static build is not working as expected. The application is embedded correctly, FrankenPHP untar it correctly, also the Caddyfile look good (it's the same i used for the "dynamic" build) but i get only 404. I've added the whole project here .

How to reproduce

git clone https://gitlab.com/ideaplexus/example-symfony-frankenphp.git
cd example-symfony-frankenphp
make build-static
make run

curl -v http://localhost:8000/greet/world

Result

{"level":"info","ts":1737119972.3083441,"logger":"http.log.access.log0","msg":"handled request","request":{"remote_ip":"172.80.0.1","client_ip":"172.80.0.1","method":"GET","host":"localhost:8000","path":"/greet/world"},"duration":0.000216366,"size":0,"status":404}

Expected

{"level":"info","ts":1737120105.7079995,"logger":"http.log.access.log0","msg":"handled request","request":{"remote_ip":"172.80.0.1","client_ip":"172.80.0.1","method":"GET","host":"localhost:8000","path":"/greet/world"},"duration":0.176928985,"size":203,"status":200}

tina-junold avatar Jan 17 '25 13:01 tina-junold

Did you try running it manually from the temporary directory to see what the issue might be?

withinboredom avatar Jan 18 '25 07:01 withinboredom

Haven't tested it myself, but the issue could also be that the Caddy config overwrites any flags you are passing to the php-server command. So you would need to explicitly define the worker script here since the Caddy config overrules the worker flag passed here

AlliBalliBaba avatar Jan 18 '25 10:01 AlliBalliBaba

@withinboredom I don't see how this should work. The temp directory is created from the static build itself and i can't run another instance of frankenphp in the same container without a different Caddyfile

@AlliBalliBaba

I've changed the static.Dockerfile to this

FROM alpine:3.21

ARG APP_NAME=app

COPY dist/${APP_NAME} /usr/local/bin/app

ENV CADDY_ADMIN=0.0.0.0:2019
ENV FRANKENPHP_CONFIG="worker ./public/index.php"

ENTRYPOINT [ "/usr/local/bin/app" ]

CMD [ "php-server" ]

This should reflect your comment since FRANKENPHP_CONFIG support setting worker like here (and I've done in the dynamic build). But with ./public/index.php and public/index.php he assume an absolute path and fails:

{"level":"warn","ts":1737349418.8005993,"msg":"PHP Warning:  Unknown: Failed to open stream: No such file or directory in Unknown on line 0","syslog_level":"warning"}
{"level":"warn","ts":1737349418.8006067,"msg":"PHP Warning:  Unknown: Failed to open stream: No such file or directory in Unknown on line 0","syslog_level":"warning"}
{"level":"error","ts":1737349418.8006103,"msg":"PHP Fatal error:  Failed opening required '/public/index.php' (include_path='.:') in Unknown on line 0","syslog_level":"err"}
{"level":"error","ts":1737349418.8006144,"msg":"PHP Fatal error:  Failed opening required '/public/index.php' (include_path='.:') in Unknown on line 0","syslog_level":"err"}
{"level":"warn","ts":1737349418.8006322,"msg":"PHP Warning:  Unknown: Failed to open stream: No such file or directory in Unknown on line 0","syslog_level":"warning"}
{"level":"error","ts":1737349418.8006423,"msg":"PHP Fatal error:  Failed opening required '/public/index.php' (include_path='.:') in Unknown on line 0","syslog_level":"err"}

tina-junold avatar Jan 20 '25 05:01 tina-junold

I think the issue could also be the current working directory. It might be necessary to start the app from the directory it's in. Have you tried something like this?

FROM alpine:3.21

ARG APP_NAME=app

COPY dist/${APP_NAME} /usr/local/bin/app

ENV CADDY_ADMIN=0.0.0.0:2019
ENV FRANKENPHP_CONFIG="worker ./public/index.php"

WORKDIR /usr/local/bin
ENTRYPOINT [ "./app" ]

CMD [ "php-server" ]

AlliBalliBaba avatar Jan 21 '25 09:01 AlliBalliBaba