A minimal web-based terminal emulator implemented in PHP. All interactions happen via one resource:
- GET /index.php → serves the UI
- POST /index.php (JSON) → executes whitelisted commands on the server via PHP handlers (no eval, no shell execution)
- Single endpoint (UI + API)
- Commands implemented as PHP functions only (no
eval
, no system command execution) - Bearer token auth (token requested on page load and stored in localStorage)
- Minimal inline HTML/CSS/JS
- Client-side command history
This project can be installed as a Composer library.
- Require it in your project:
composer require spike/php-web-terminal
- Publish or serve the included web entry point
index.php
, or embed the services in your own controller.
Autoloading follows PSR-4: the App\\
namespace maps to src/
.
<?php
use SpikeTerminal\Application\{TerminalService};
use SpikeTerminal\Application\CommandRegistry;
require __DIR__ . '/vendor/autoload.php';
$registry = new CommandRegistry();
$registry->register(new SomeCommand($registry));
- Ensure PHP 8.1+ is installed.
- From the project root, start the PHP dev server:
php -S localhost:8000
- Open http://localhost:8000/ in your browser.
- Ensure Docker and Docker Compose are installed.
- From the project root, start the service:
docker compose up
- Open http://localhost:8000/ in your browser.
- Stop with Ctrl+C, or run in the background with
-d
and stop withdocker compose down
.
The sandbox directory storage/
is created automatically (a sample readme.txt
is included).
- All commands are server-side PHP handlers; there is no
eval()
and no OS shell execution. - In production, use signed JWTs and HTTPS.
The single endpoint remains /index.php
, but the logic is refactored into layers under src/
:
- Domain:
App\Domain
— core contracts (e.g.,CommandInterface
). - Application:
App\Application
— orchestration and use-cases (e.g.,TerminalService
,CommandRegistry
). - Presentation:
App\Presentation
— HTTP controller (TerminalController
) that render the UI (GET). - Commands:
App\Commands
— each command is a class implementingCommandInterface
.
To add or modify commands:
- Create a class in
src/Commands
implementingApp\\Domain\\CommandInterface
withname()
andexecute(array $args): string
. - Register it in
index.php
via$registry->register(new YourCommand(...deps...));
before the controller handles the request.
- No use of
eval()
or OS shell execution. All commands are pure PHP.