On this page
System Requirements
Legion Engine runs on any standard cPanel shared hosting environment. No special configuration needed beyond what most hosts provide by default.
| Component | Minimum | Recommended | Notes |
|---|---|---|---|
| PHP | 8.1 | 8.2+ | PDO, GD, cURL, mbstring required |
| MySQL | 5.7 | 8.0+ | InnoDB engine recommended |
| Web Server | Apache 2.4 | Apache 2.4+ | mod_rewrite, .htaccess enabled |
| Disk | 50 MB | 500 MB+ | Plus space for uploads |
| cURL | Required | - | For external API calls |
Installation
Legion uses a shell-script deployment system. The process takes under 2 minutes on any server with SSH access.
1. Clone the workspace
The ai_test workspace contains all scripts, configurations, and documentation. Clone it to your local machine.
2. Create project config
Add a JSON file at config/projects/YOUR_PROJECT.json with server credentials, database name, and the project path on the server.
3. Run deploy.sh
The deploy script finds the latest Legion version, creates the database and user via cPanel UAPI, extracts the engine, and configures everything automatically.
4. Run reset_legion.sh
This generates the standard project structure: views, assets, API folder, custom engine hooks, and registers the project with the distributor.
5. Run brand_setup.sh
Configure fonts, colors, site name, and identity from a brand JSON file. Takes under 30 seconds.
Project Structure
Every Legion project follows the same structure. Understanding it is essential before writing any code.
Key Directories
- legion/project/public/views/ — All PHP view files go here
- legion/project/public/assets/css/ — CSS files: main.css, rtl.css, responsive.css
- legion/project/public/api/ — Custom API endpoints
- legion/project/private/custom_engine/backend/ — Custom PHP hooks and config
- legion/engine/ — Core engine — never modify directly
CSS Organization Rule
- main.css — All base LTR styles
- rtl.css — Arabic-only overrides
- responsive.css — Breakpoints only (1199px tablet, 575px mobile)
Working with Modules
Modules are the core building block of Legion. Each module is a complete data entity with its own database table, panel, and API.
Create a Module
Use create_module.sh with a JSON payload defining the module name, prefix, and fields. The script calls the Legion API to generate the module remotely.
Modify a Module
Use modify_module.sh to add or remove fields. Always fetch the latest module version first via the API before making changes.
Holy Rules for Modules
- NEVER modify the database directly — always use module scripts
- Always populate field_tip_translation and field_help_translations
- NEVER use JS alert() — use End::json() + msg() instead
Database Operations
Legion provides a clean OO query builder and Model class for all database interactions.
Adding an Entry
Use the Model class to add entries. Always call co() before process() — co() generates date_created, time_stamp, and validates required fields.
Querying Data
Use the DB class for OO queries. Set where, params, order, limit, and call process(). Access results via $db->data and count via $db->count.
Raw SQL
For complex queries, use DB::query() with prepared statement parameters. Never concatenate user input into SQL strings.
API Endpoints
Create custom API endpoints by placing PHP files in legion/project/public/api/ENDPOINT_NAME/index.php. Accessible at /api/ENDPOINT_NAME/.
Response Format
Always use End::json() to return responses. The third positional parameter is data — use the named parameter custom_desc: for messages.
Authentication
Check user session with Auth::isLogged(). For mobile/API requests, validate the token passed in headers using the built-in session management.