Convert the php image to WASM
$ c2w php:8.1-cli-alpine3.16 /tmp/out/out.wasm
Run it on the runtime:
$ wasmtime -- /tmp/out/out.wasm -- -r 'print("hello world\n");'
hello world
This passes -r 'print("hello world\n");'"
argument to php
(entrypoint of this image) and hello world
is printed.
The following runs the WASI-converted container image on browser.
Run this at the project repo root directory.
$ c2w php:8.1-cli-alpine3.16 /tmp/out-js2/htdocs/out.wasm
$ cp -R ./examples/wasi-browser/* /tmp/out-js2/ && chmod 755 /tmp/out-js2/htdocs
$ docker run --rm -p 8080:80 \
-v "/tmp/out-js2/htdocs:/usr/local/apache2/htdocs/:ro" \
-v "/tmp/out-js2/xterm-pty.conf:/usr/local/apache2/conf/extra/xterm-pty.conf:ro" \
--entrypoint=/bin/sh httpd -c 'echo "Include conf/extra/xterm-pty.conf" >> /usr/local/apache2/conf/httpd.conf && httpd-foreground'
You can run the container on browser via localhost:8080
.
PHP REPL will start on browser (you might need to wait a while untils the prompt is printed).
Please see wasi-browser example for details about WASI-on-browser.
--to-js
provides emscripten-compiled image runnable on browser.
$ c2w --to-js php:8.1-cli-alpine3.16 /tmp/phpjs/htdocs/
Run it on browser:
Run this at the project repo root directory.
$ cp -R ./examples/emscripten/* /tmp/phpjs/ && chmod 755 /tmp/phpjs/htdocs
$ docker run --rm -p 8080:80 \
-v "/tmp/phpjs/htdocs:/usr/local/apache2/htdocs/:ro" \
-v "/tmp/phpjs/xterm-pty.conf:/usr/local/apache2/conf/extra/xterm-pty.conf:ro" \
--entrypoint=/bin/sh httpd -c 'echo "Include conf/extra/xterm-pty.conf" >> /usr/local/apache2/conf/httpd.conf && httpd-foreground'
You can run the container on browser via localhost:8080
.
PHP REPL will start on browser (you might need to wait a while untils the prompt is printed).
NOTE: It can take some time to load and start the container.