WordPress / wordpress-playground

Run WordPress in the browser via WebAssembly PHP
https://w.org/playground/
GNU General Public License v2.0
1.62k stars 249 forks source link

Explore creating pure PHP dev server for Playground #1294

Open brandonpayton opened 5 months ago

brandonpayton commented 5 months ago

In #1197, we ported existing htaccess rules to PHP in order to serve from an nginx-based host where we do not actual control nginx config. (In that case, all files are served via PHP, and edge caching is enabled so that PHP only needs to run when the cache is being primed.)

This work led to an idea by @adamziel that maybe we could leverage a similar approach to provide a standalone dev server for Playground or within Playground.

bgrgicak commented 5 months ago

In case it helps, I like to use this Docker command to start a local dev server. This won't load Playground, but it will load pages like the PR preview and allow you to test PHP scripts (proxy, logger).

I assume that we could get everything running, by mounting the correct public folders.

docker run -d -p 8787:80 -v "$PWD/packages/playground/website/public":/var/www/html php:8.0-apache

adamziel commented 5 months ago

A local dev server still needs a JS bundler to bundle all the JS code, and with Vite we need to use its dev server.

What I had in mind was taking the build and bundled output, so the same set of files as we'd deploy on playground.wordpress.net, and serving that using the CLI Playground. The PHP server package could help us with that.

At first, it would be just a cool gimmick – you can run the in-browser Playground locally without a million node packages. Then it could potentially make it easy to host Playground on most PHP hostings. Then, we could bundle that server as a single executable and you no longer need node to work with Playground locally. Finally, and I'm not sure what's the application of that, but we could explore running the same PHP code on the server and in the browser as in we'd have an isomorphic PHP app.