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. Build Assets for Production

If you opted to use the Vite & Tailwind CSS v4 pipeline for dynamic assets, you MUST compile your resources for production before deploying. Running the build compiles, bundles, and minifies your source files (from resources/) and writes them directly into the standard public/ folder for high-speed serving:

Terminal Command

npm run build
          

Note: In production mode (DEBUG=False), the asset() and public() template helpers will instantly serve these optimized compiled assets directly with zero performance overhead.

7. 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.
Production Configurator

Production Configurator

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