Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Static Build with Symfony Application - 404 for all routes #1334

Open
tina-junold opened this issue Jan 17, 2025 · 4 comments
Open

Static Build with Symfony Application - 404 for all routes #1334

tina-junold opened this issue Jan 17, 2025 · 4 comments

Comments

@tina-junold
Copy link

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}
@withinboredom
Copy link
Collaborator

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

@AlliBalliBaba
Copy link
Collaborator

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

@tina-junold
Copy link
Author

@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"}

@AlliBalliBaba
Copy link
Collaborator

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" ]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants