Closed logosur closed 5 months ago
./my-app php-cli bin/console
I believe this isn't running code INSIDE the binary, but in whatever shell you are currently running in. So wherever you are running it, there is no bin/console
.
Currently, static builds are broken for just about everyone (#709, #710) due to an upstream library so it'll probably be a minute before we can try helping out more in-depth.
I believe though, that you just need to run:
./my-app run
as
./my-app php-server
will start a PHP server from your current directory.
Either way, I like the way you're thinking and agree that it probably should work the way you're trying to use it.
@dunglas what do you think about this (pseudocode):
if is_embedded():
embedded_dir := extract()
chdir(embedded_dir)
// continue as normal
for all cli commands?
(happy to create a pr)
Though probably we want to disable php-server
in an embedded context ... I suspect run
or start
would be the preferred method.
I didn't do that in the beginning on purpose for a reason that I cannot remember 😅 I'll try to figure out.
Using php-server
looks safer to me. This allows to use Caddy as usual in other contexts. I don't want to highjack too much standard Caddy behaviors.
Hi @dunglas , but in your website you claim that the php code is embedded in the binary, also I can see in the builder script that all the app code is tarred in .tar file, why when I run the command ./my-app php-server -l 127.0.0.1:8081
this is serving my localhost storage content instead of the app itself ?
Thanks !
I didn't do that in the beginning on purpose for a reason that I cannot remember
I mean, it makes sense logically that you did it that way. It's regular 'ole frankenphp that knows how to serve the embedded app...
Just to scope creep a bit, it'd be really cool if you could embed a "command manifest" in the composer.json
or a frankenphp.json
file that the cli would embed separately during the build (maybe just using regular go embeds?) and then allow you to do something like:
{
"console": { "run": "bin/console", "description": "Symfony console" }
}
Then the output of the embedded app:
Available Commands:
adapt Adapts a configuration to Caddy's native JSON
add-package Adds Caddy packages (EXPERIMENTAL)
build-info Prints information about this build
completion Generate completion script
console Symfony console <-----
environ Prints the environment
file-server Spins up a production-ready file server
fmt Formats a Caddyfile
...
Then other commands would/could behave like normal. Even allow overriding existing commands with either a custom command or null
to "strip" it out of the possible commands:
{ "adapt": null }
I dunno though, at this point I'm thinking this scope creep has creeped far and away from caddy anything. So maybe not... Interesting idea though.
@logosur it is! I'll try to figure out what's your issue tomorrow.
@withinboredom Ok got it! Indeed that would be nice. I'm working on extension auto detection for standalone binaries, that Ill parse the composer.json file, so composer.json would be a good place to add such features!
./my-app php-cli bin/console
I believe this isn't running code INSIDE the binary, but in whatever shell you are currently running in. So wherever you are running it, there is no
bin/console
.Currently, static builds are broken for just about everyone (#709, #710) due to an upstream library so it'll probably be a minute before we can try helping out more in-depth.
I believe though, that you just need to run:
./my-app run
as
./my-app php-server
will start a PHP server from your current directory.
Either way, I like the way you're thinking and agree that it probably should work the way you're trying to use it.
Can I run an ftp server inside my binary? I need to figure out how to upload some image files to my public folder like we can do normally with apache and php fpm.
Can I run an ftp server inside my binary?
Um, technically yes, if you write an ftp server (or use a caddy module, if there is one) and carefully compile it ... anything is theoretically possible; it's software afterall. We're (probably, very) unlikely to create such a feature.
I need to figure out how to upload some image files to my public folder like we can do normally with apache and php fpm.
Using an embedded php app probably isn't the best way to go about that. If you just need to add some images, you can add them to the app before embedding the app. If while running the app, you need to mutate the app (add images, change files, etc) then an embedded app is NOT a proper solution for your app. The files live "inside" the executable and are mostly immutable.
Hello, I created the binary file and tried to run it.
I used ./my-app php-server command to run it. In the terminal, it looks like it started but in the browser localhost, I can't see my app is running. But in browser
I also tried run and start but not work.
here I used run but sill nothing on localhost also visited localhost:2019 but got page not found
I am not an expert on it and also not as much expert on Linux. here is the loom video that I tried. If you could help me I will be blessed.
Loom video: https://www.loom.com/share/a8c46cd7756148b3bad634d9b6b7bc03
The Dockerfile seems broken and not similar to the official one: https://frankenphp.dev/docs/embed/#creating-a-linux-binary
Especially, the call to export
mixed in the build command cannot work.
Also, the app should be prepared on your host, using the proper PHP version, not in the Docker image.
I tried to bundle an app by following the docs, and it works.
Closing for now, feel free to re-open if you still have issue by using the documented and recommended way.
@skmirajbn try http://localhost
in your browser (notice that there is no s in http://
). Modern browsers always use HTTPS by default, so you have to explicitly add the HTTP scheme.
First I tried this docker file as in the document but got error about on git like this issue: https://github.com/dunglas/frankenphp/issues/680
Then I get solved as instructed on this issue to add a new line export FRANKENPHP_VERSION=1.1.2 \
I followed that binery is successfully created. but then this issue here occurred.
Ok, I will create a new issue let see. If this can be fixed. 😒
Please copy your entire Dockerfile. #680 was because the second WORKDIR
directive was missing in the Dockerfile of the user, and it is mandatory.
If I use this docker file then got error about git.
And so I tried this of #680 from this person dockerfile But this time get stack on this place.
here is the terminal logs skmiraj@skmiraj-VirtualBox:~/Desktop/projectsourcecode/laravelfranken$ sudo docker build -t static-app -f static-build.Dockerfile .
[sudo] password for skmiraj:
[+] Building 2776.3s (11/12) docker:default
=> [internal] load build definition from static-build.Dockerfile 0.2s
=> => transferring dockerfile: 504B 0.1s
=> [internal] load metadata for docker.io/dunglas/frankenphp:static-buil 2.7s
=> [internal] load .dockerignore 0.2s
=> => transferring context: 2B 0.0s
=> [1/8] FROM docker.io/dunglas/frankenphp:static-builder@sha256:4cb4088 0.0s
=> [internal] load build context 2.3s
=> => transferring context: 736.26kB 2.2s
=> CACHED [2/8] WORKDIR /go/src/app/dist/app 0.0s
=> [3/8] COPY . . 5.7s
=> [4/8] RUN rm -rf tests/ 1.4s
=> [5/8] WORKDIR /go/src/app/ 0.6s
=> [6/8] RUN git clone https://github.com/dunglas/frankenphp 5.9s
=> [7/8] WORKDIR /go/src/app/frankenphp 0.6s
=> [8/8] RUN EMBED=../dist/app/ ./build-static.sh 2756.3s
=> => # PKG_CONFIG='pkg-config'
=> => # GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=
=> => # 0 -ffile-prefix-map=/tmp/go-build4142773356=/tmp/go-build -gno-record-
=> => # gcc-switches'
=> => # Ultimate Packer for eXecutables
=> => # Copyright (C) 1996 - 2023
What happened?
I've been following instructions on how to build docker and generate an standalone binary from symfony project, then move it out to my local machine and then try to make it serve content. But as much I try it, it seems that source symfony project is not in the executable and also it seems to be serving my local paths, not the content in the executable itself. I've even tried the demo project at https://github.com/dunglas/frankenphp-demo and still the same result...
When I try to execute console, this neither works: ./my-app php-cli bin/console
Thanks !
Commands:
static-build.Dockerfile:
Build Type
Standalone binary
Worker Mode
No
Operating System
GNU/Linux
CPU Architecture
x86_64
PHP configuration
Relevant log output