Skip to main content
The serve command starts a local development server for your Lyger application.

Syntax

php rawr serve [--port=PORT]
--port
integer
default:"8000"
Specify a custom port number for the server

Basic Usage

Start the server on the default port (8000):
php rawr serve
Output:
[Lyger] PHP Server running on http://localhost:8000
   Press Ctrl+C to stop

Custom Port

Start the server on a custom port:
php rawr serve --port=8080
The server will be accessible at http://localhost:8080

Server Modes

Lyger supports two server modes:

1. PHP Built-in Server (Default)

The default mode uses PHP’s built-in development server:
php rawr serve
# or explicitly
php rawr serve:php
This mode is perfect for local development and testing. It automatically serves files from the public/ directory.

2. Always-Alive Mode (Rust + FFI)

For production-like performance during development, Lyger can use the Rust HTTP server via FFI:
php rawr serve
Always-Alive mode requires:
  • FFI extension enabled in php.ini
  • Rust library compiled (liblyger.so, liblyger.dylib, or liblyger.dll)

Server Configuration

PHP Configuration

Create a php.ini file in your project root for custom PHP settings:
php.ini
[PHP]
ffi.enable = 1
memory_limit = 256M
max_execution_time = 60
The server automatically loads this configuration:
rawr (lines 138-150)
function serveLegacy(string $basePath, string $phpIni, string $port = '8000'): void
{
    $publicPath = $basePath . '/public';
    
    // Build absolute path for php.ini before changing directory
    $phpIniAbs = realpath($phpIni) ?: $phpIni;
    $iniFlag = file_exists($phpIni) ? "-c \"{$phpIniAbs}\"" : '';
    
    echo "\n[Lyger] PHP Server running on http://localhost:{$port}\n";
    echo "   Press Ctrl+C to stop\n\n";
    
    // Execute PHP server with absolute paths
    $cmd = "php {$iniFlag} -S localhost:{$port} -t \"{$publicPath}\"";
    passthru($cmd);
}

Document Root

The server serves files from the public/ directory:
your-project/
├── public/              # Web root (served by server)
│   ├── index.php       # Entry point
│   ├── assets/
│   └── uploads/
├── App/
├── Lyger/
└── rawr

Health Check Endpoints

When using Always-Alive mode, Lyger provides built-in health check endpoints:

/api/health

Check server status and memory usage:
curl http://localhost:8000/api/health
Response:
{
  "status": "ok",
  "memory": "12.5 MB"
}

/api/info

Get server information:
curl http://localhost:8000/api/info
Response:
{
  "framework": "Lyger v0.1",
  "mode": "always-alive",
  "php_version": "8.2.0"
}

Stopping the Server

Press Ctrl+C in the terminal to stop the server:
^C
[Lyger] Server stopped

Common Use Cases

Development with Hot Reload

For frontend development with live reloading:
# Terminal 1: Start Lyger backend
php rawr serve --port=8000

# Terminal 2: Start frontend dev server
npm run dev

Multiple Projects

Run multiple Lyger projects simultaneously using different ports:
# Project 1
cd project1
php rawr serve --port=8000

# Project 2
cd project2
php rawr serve --port=8001

Testing API Endpoints

Start the server and test your API:
php rawr serve

Troubleshooting

Port Already in Use

If port 8000 is already in use:
php rawr serve --port=8001
Or find and kill the process using the port:
# Find process
lsof -i :8000

# Kill process
kill -9 <PID>

Permission Denied

Ensure the public/ directory has proper permissions:
chmod -R 755 public/

FFI Not Available

If you see FFI-related warnings, enable it in php.ini:
[PHP]
ffi.enable = 1
Then restart the server.

Performance Notes

The PHP built-in server is single-threaded and intended for development only. For production, use:
  • Nginx + PHP-FPM
  • Apache + mod_php
  • Caddy with PHP FastCGI

Next Steps

Make Controller

Create controllers to handle requests

Routing

Define routes for your application

Configuration

Configure your application settings

Deployment

Deploy to production