Deployment to Production

Linux Server (with systemd)

To deploy your Lila application on a Linux server, it's recommended to use a virtual environment and a systemd service to manage the process.

1. Create a Virtual Environment

Terminal

python -m venv venv
source venv/bin/activate
pip install -r requirements.txt
pip install lila-framework
          

2. Create a Start Script

start_lila.sh

#!/bin/bash
source /path/to/your/project/venv/bin/activate
python /path/to/your/project/main.py
                        

3. Create a systemd Service

/etc/systemd/system/lila.service

[Unit]
Description=Lila Framework Service
After=network.target

[Service]
User=your_user
Group=your_group
WorkingDirectory=/path/to/your/project
ExecStart=/path/to/your/project/start_lila.sh
Restart=always
RestartSec=10
Environment=PATH=/path/to/your/project/venv/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
Environment=PYTHONPATH=/path/to/your/project

[Install]
WantedBy=multi-user.target
                        

4. Enable and Start the Service

Termial

sudo systemctl daemon-reload
sudo systemctl enable lila.service
sudo systemctl start lila.service
chmod +x /path/to/your/project/start_lila.sh

                        

5. Disable Debug Mode

In your `.env` file, make sure to set `DEBUG=False` for production.

.env
 
DEBUG=False
                        

Important Error Handling Details: When DEBUG=True, the framework's internal App class will automatically intercept 500 Internal Server Errors and display a highly detailed HTML page in your browser showing the exact line of code, file path, and a full traceback of the exception.

When you deploy to production and set DEBUG=False, Lila will seamlessly hide this sensitive traceback data and instead render a generic user-friendly 500 Error page. Furthermore, 404 Not Found errors will automatically look for your custom template defined in PATH_TEMPLATE_NOT_FOUND.

6. Configure Nginx (Optional)

/etc/nginx/sites-available/your-domain.com

server {
    listen 80;
    listen [::]:80;
    server_name your-domain.com www.your-domain.com;

    # Redirect all HTTP traffic to HTTPS
    return 301 https://$host$request_uri;
}

server {
    listen 443 ssl;
    listen [::]:443 ssl;
    server_name your-domain.com www.your-domain.com;

    # SSL Certificates
    ssl_certificate /etc/nginx/ssl/your-domain.com/your-domain.com.crt;
    ssl_certificate_key /etc/nginx/ssl/your-domain.com/your-domain.com.key;

    # Lila Framework Reverse Proxy in port 3002
    location / {
        proxy_pass http://127.0.0.1:3002;
        proxy_http_version 1.1;
        
        # WebSockets and Connection Headers
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;

        # Timeouts for long-running connections
        proxy_read_timeout 60s;
        proxy_send_timeout 60s;
    }
}
          

Windows Server

On Windows, you can use the Task Scheduler to run your application at startup.

  1. Create a `.bat` or `.ps1` script to start your application.
  2. Open Task Scheduler and create a new task that runs at system startup.
  3. Set the action to run your script.

Docker & VPS Deployment

Each Lila project includes a production-ready, highly optimized multi-container Docker stack (Python app, low-memory MySQL 8.0, Redis cache/sessions, and Nginx reverse proxy).

⚡ MySQL Low-Memory Tuning (~70MB RAM footprint)

Default MySQL 8.0 consumes 450MB - 800MB+ RAM. Lila ships with a custom docker/mysql/my.cnf that disables performance_schema, tunes InnoDB buffers, and reduces the memory footprint to just ~60MB - 90MB. This makes it effortless to run multiple Lila applications on affordable 1GB or 2GB RAM VPS instances without hitting OOM crashes.

1. Pre-Flight Diagnostics & Port Check

Verify that Docker is running and that your configured ports in .env are available:

lila-docker check

2. Build the Production Image

Builds the secure, non-root Python 3.12 production image with layer caching:

lila-docker build

3. Start the Stack (Dev or Prod)

# Development: start MySQL + Redis only (run app locally via lila-dev)
lila-docker start

# Production: start full production stack (MySQL + Redis + App + Nginx)
lila-docker start prod

4. Live Resource & Memory Monitoring

Monitor real-time CPU, RAM usage, and limits for all project containers:

lila-docker stats

5. Automated VPS Zero-Downtime Deploy

Pulls latest Git changes, rebuilds Docker images, runs migrations, and restarts services:

lila-docker deploy

6. View Container Logs & Status

# Check container status
lila-docker ps

# Tail Python app logs
lila-docker logs

# Tail MySQL logs
lila-docker logs mysql

# Tail Nginx logs
lila-docker logs nginx

7. Run CLI Commands inside Docker

lila-docker exec app bash

# Inside the container:
lila-migrations migrate
lila-model create MyModel

8. Connect to MySQL / Redis Terminals

# Connect to MySQL shell using credentials from .env
lila-docker mysql
lila-docker db # alias

# Connect to Redis CLI:
lila-docker redis

9. VPS Disk Maintenance & Cleanup

# Check Docker disk space usage
lila-docker df

# Clean up orphaned volumes, dangling images, and build cache
lila-docker prune
lila-docker clean -f

10. Multi-Project VPS Reverse Proxy (Host Nginx)

Configure a different PORT, DB_PORT, and LILA_PROJECT_NAME in each project's .env file:

# Project A (.env): PORT=8001, DB_PORT=3307, LILA_PROJECT_NAME=shop
# Project B (.env): PORT=8002, DB_PORT=3308, LILA_PROJECT_NAME=blog

# In Host Nginx configuration:
server {
    listen 80;
    server_name shop.example.com;

    location / {
        proxy_pass http://127.0.0.1:8001;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}
Production Configurator

Production Configurator

Fill in your server details to automatically update the snippets above.