🧩 PHP WASM Builder compiles PHP and a Symfony app to WebAssembly for the browser
In brief
- 🧩 The open-source tool builds PHP as WebAssembly for browser and Node, with the chosen PHP version and extensions.
- 📦 Your own code and its vendor folder are embedded in the .wasm file.
- 🧪 Examples run in the browser, including the Symfony Demo with Doctrine and SQLite.
- 🔓 MIT license; the builds run through Docker.
PHP WASM Builder is an open-source project that compiles PHP to WebAssembly, so PHP code runs in a browser, in a Web Worker or in Node. You choose the PHP version (the project page lists 8.3 to 8.6) and the extensions, such as SQLite, intl, OpenSSL or opcache. Your own code and its vendor directory are embedded in the .wasm file. On a web page, a few lines of JavaScript are enough to run PHP code, according to the project page. The examples that run in the browser include the official Symfony Demo and a Symfony application with Doctrine, forms and a session.
The workflow according to the README: Docker builds PHP into a directory such as build/php-8.6/, and Node runs it, for example with the command docker buildx bake node. On a web page you import the generated file php-web.mjs, create a PHP instance with createPhp() and execute code with runCode(); the output comes back as stdout. Anyone who wants to build PHP for their own project will find the section "Use it in your project" in the documentation.
The project page lists examples that run directly in the browser, with their code in an examples/ directory: the official Symfony Demo, a blog with admin area, Doctrine and SQLite, Stimulus and 30 languages; the back office of a fictional record shop with a sales dashboard, filters and batch actions; a Symfony application whose input is still there after a reload because files can persist; and small tools that fix Markdown, improve the microtypography of HTML text, or validate a page's structured data against schema.org and the Google Rich Results requirements. There are also the slides of a talk about the builder, in French and English, that run PHP live.
On origins, the repository says the builder was created by Derick Rethans for The PHP Foundation in derickr/php-wasm-builder, the builder of the PHP WASM files of the php.net documentation. The part that runs PHP, docker/run.c, comes from the work of Antoine Bluchet. Both are under the MIT license. The repository described here is lyrixx/php-wasm-builder, with the site at lyrixx.github.io/php-wasm-builder. The page names no price and no limits; to use it you need Docker to produce the builds.