> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/betoalien/Lyger-PHP-Framework/llms.txt
> Use this file to discover all available pages before exploring further.

# Installation

> Get Lyger PHP Framework installed and configured on your system

Lyger is a high-performance PHP framework with Rust FFI integration that combines the simplicity of PHP with the speed of Rust. This guide will walk you through installing and configuring Lyger on your system.

## Requirements

Before installing Lyger, ensure your system meets these requirements:

<CardGroup cols={2}>
  <Card title="PHP 8.0 or higher" icon="php">
    Lyger requires PHP 8.0 or later with modern PHP features
  </Card>

  <Card title="FFI Extension" icon="bolt">
    The FFI extension must be enabled for Rust integration
  </Card>
</CardGroup>

### PHP Version Check

```bash theme={null}
php -v
```

You should see PHP 8.0 or higher in the output.

## Installation Steps

<Steps>
  <Step title="Clone the Repository">
    Clone the Lyger Framework repository from GitHub:

    ```bash theme={null}
    git clone https://github.com/betoalien/Lyger-PHP-Framework.git
    cd Lyger-framework
    ```
  </Step>

  <Step title="Enable FFI Extension">
    Create a `php.ini` file in the root directory of your project:

    ```ini php.ini theme={null}
    [PHP]
    ffi.enable = 1
    ```

    <Note>
      The FFI extension is required for Lyger's Rust integration, which provides high-performance features like Always-Alive server mode and zero-copy database operations.
    </Note>
  </Step>

  <Step title="Install Dependencies">
    Install PHP dependencies using Composer:

    ```bash theme={null}
    composer install
    ```

    If you don't have Composer installed globally, Lyger includes a local copy:

    ```bash theme={null}
    php composer.phar install
    ```
  </Step>

  <Step title="Run the Interactive Installer (Optional)">
    Lyger includes a Zero-Bloat installer that configures your stack and removes unused components:

    ```bash theme={null}
    php rawr install
    ```

    The installer will guide you through:

    * **Architecture**: API Headless or Full-Stack
    * **Frontend**: Vue.js, React, or Svelte (if Full-Stack)
    * **Database**: PostgreSQL, MySQL, or SQLite
    * **Authentication**: Lyger Session, JWT, or None

    <Warning>
      The installer removes unused files to keep your project lean. This is a one-time setup that cannot be undone.
    </Warning>
  </Step>

  <Step title="Verify Installation">
    Start the development server:

    ```bash theme={null}
    php rawr serve
    ```

    Visit `http://localhost:8000` in your browser. You should see the Lyger welcome page.
  </Step>
</Steps>

## Configuration

### Environment Setup

Copy the example environment file and configure your settings:

```bash theme={null}
cp .env.example .env
```

Edit the `.env` file to configure your application:

<CodeGroup>
  ```env SQLite (Default) theme={null}
  # Application
  APP_NAME="Lyger Framework"
  APP_ENV=local
  APP_DEBUG=true
  APP_URL=http://localhost:8000

  # Database
  DB_CONNECTION=sqlite
  DB_DATABASE=database/database.sqlite
  ```

  ```env PostgreSQL theme={null}
  # Application
  APP_NAME="Lyger Framework"
  APP_ENV=local
  APP_DEBUG=true
  APP_URL=http://localhost:8000

  # Database
  DB_CONNECTION=postgres
  DB_HOST=127.0.0.1
  DB_PORT=5432
  DB_DATABASE=lyger
  DB_USERNAME=postgres
  DB_PASSWORD=
  ```

  ```env MySQL theme={null}
  # Application
  APP_NAME="Lyger Framework"
  APP_ENV=local
  APP_DEBUG=true
  APP_URL=http://localhost:8000

  # Database
  DB_CONNECTION=mysql
  DB_HOST=127.0.0.1
  DB_PORT=3306
  DB_DATABASE=lyger
  DB_USERNAME=root
  DB_PASSWORD=
  ```
</CodeGroup>

### Supported Databases

Lyger supports multiple database engines through its Rust-powered query builder:

* **SQLite** - Best for development and small applications
* **PostgreSQL** - Best for complex queries and analytics
* **MySQL** - Best for write-heavy CRUD applications
* **MariaDB** - Compatible with MySQL configuration
* **MongoDB** - NoSQL document database

### Additional Configuration

The `.env` file includes other configuration options:

```env .env theme={null}
# API Configuration
API_PREFIX=api
API_VERSION=v1

# Authentication
AUTH_TOKEN=your-secret-token-here
TOKEN_EXPIRY=3600

# CORS Configuration
CORS_ALLOWED_ORIGINS=*
CORS_ALLOWED_METHODS=GET,POST,PUT,DELETE,OPTIONS
CORS_ALLOWED_HEADERS=Content-Type,Authorization,X-Requested-With

# Rate Limiting
RATE_LIMIT_MAX_ATTEMPTS=60
RATE_LIMIT_DECAY_SECONDS=60

# Rust FFI
FFI_LIB_PATH=libraries/liblyger.dylib

# Logging
LOG_LEVEL=debug
LOG_FILE=logs/lyger.log
```

## Directory Structure

After installation, your Lyger project will have the following structure:

```
Lyger-framework/
├── App/
│   ├── Controllers/       # Application controllers
│   └── Models/           # Database models
├── Lyger/                # Framework core
│   ├── Routing/          # Router and route handling
│   ├── Http/             # Request and Response
│   ├── Database/         # ORM and query builder
│   └── ...
├── public/               # Web server document root
│   └── index.php         # Application entry point
├── routes/
│   └── web.php          # Route definitions
├── database/
│   └── migrations/      # Database migrations
├── vendor/              # Composer dependencies
├── .env                 # Environment configuration
├── composer.json        # Composer configuration
├── php.ini             # PHP configuration
└── rawr                # CLI tool
```

## Server Modes

Lyger offers two server modes:

### PHP Built-in Server (Default)

```bash theme={null}
php rawr serve

# Custom port
php rawr serve --port=8080
```

This mode uses PHP's built-in development server.

### Legacy Mode

```bash theme={null}
php rawr serve:php
```

Alternative command for the PHP built-in server.

<Note>
  The Always-Alive server mode with Rust HTTP server is available when the FFI extension is enabled and the Rust library is compiled.
</Note>

## Troubleshooting

### FFI Extension Not Found

If you see an error about the FFI extension:

1. Check if FFI is available: `php -m | grep FFI`
2. If not available, install it via your package manager:
   * Ubuntu/Debian: `sudo apt-get install php-ffi`
   * macOS (Homebrew): FFI is included in PHP 8.0+
3. Ensure `ffi.enable = 1` is in your `php.ini`

### Composer Install Fails

If Composer installation fails:

```bash theme={null}
# Use the bundled Composer
php composer.phar install

# Or update Composer
php composer.phar self-update
```

### Port Already in Use

If port 8000 is already in use:

```bash theme={null}
php rawr serve --port=3000
```

## Next Steps

Now that you have Lyger installed, you're ready to build your first application:

<CardGroup cols={2}>
  <Card title="Quickstart Guide" icon="rocket" href="/quickstart">
    Build your first Lyger application
  </Card>

  <Card title="Routing" icon="route" href="/routing/basic-routing">
    Learn about routing and controllers
  </Card>

  <Card title="Database" icon="database" href="/database/getting-started">
    Work with models and migrations
  </Card>

  <Card title="CLI Commands" icon="terminal" href="/cli/overview">
    Explore the Rawr CLI tool
  </Card>
</CardGroup>
