Sometimes I use a random online PHP interpreter to execute a simple PHP block of code quickly. Occasionally, I wondered, "Is it really complicated to implement such an online platform? How does it work?" ๐ค
From that question, I tried to figure it out by implementing this fun side project.
Turned out, it's not that hard. ๐ค
Here is how it works:
- From the editor in the browser I send the code in the back-end
- I create a temporary
PHP
file - I execute it with the
PHP interpreter
on the server - I return the output and show it in the browser
That's literally it! ๐
This project has already Laravel sail
installed as a dependency. So, you can easily use Docker to boot it up.
You can run the following commands:
composer install
./vendor/bin/sail up
npm run dev
By default, Laravel sail runs the project in the 80
port. So, you can access it via http://localhost
. But you can add a separate port in APP_PORT
in .env
file.
The UI and implementation of this project is largely inspired from an excellent project called PHPAST by Ryan Chandler.
This project is intended for experiment. There might be some security issues. Because this is just executing anything is sent from the browswer.
So, DON'T RUN THIS ON YOUR PRODUCTION SERVER, unless you take necessary security measures!
Ideas and contributions are welcome! ๐