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
python -m venv venv
source venv/bin/activate
pip install -r requirements.txt
pip install lila-framework
2. Create a Start Script
#!/bin/bash
source /path/to/your/project/venv/bin/activate
python /path/to/your/project/main.py
3. Create a systemd 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
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.
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)
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.
- Create a `.bat` or `.ps1` script to start your application.
- Open Task Scheduler and create a new task that runs at system startup.
- Set the action to run your script.
Docker Deployment Workflow
Each Lila project comes preconfigured with a multi-container Docker structure that packages both the Python app (with Python 3.14-slim) and a MySQL database into isolated containers.
All container and network names are automatically prefixed with LILA_PROJECT_NAME (which you define
in your .env file at scaffolding). This keeps them fully isolated, allowing you to deploy multiple
distinct Lila projects on the same VPS without port or namespace conflicts.
1. Build the Production Image
Run this to build the lightweight Python 3.14 production image, caching dependencies for faster rebuilds:
lila-docker build
2. Start the Stack (MySQL & App)
To start both the MySQL database and the Python app container in production mode (headless/daemon):
lila-docker start prod
3. View Container Logs & Status
# Check container status
lila-docker ps
# Tail Python app logs
lila-docker logs
# Tail MySQL logs
lila-docker logs mysql
4. Run CLI Commands inside Docker
To run migrations or scaffold models inside your running production container, use
lila-docker exec:
lila-docker exec app bash
# Inside the container shell:
lila-migrations
lila-model create MyModel
5. Connect to MySQL Terminal
Connect directly to the interactive MySQL shell using credentials from .env:
# Conectar a MySQL usando las credenciales y BD del .env del proyecto
lila-docker mysql
# o usando el alias corto:
lila-docker db
# Conectar como usuario root usando el password root del .env
lila-docker mysql --root
# Especificar/sobrescribir usuario, contraseƱa o BD si es necesario
lila-docker mysql -u root -p mi_password -d mi_base_de_datos
6. VPS Disk Maintenance & Cleanup
To prevent unused images, dangling volumes, and BuildKit cache from filling up your VPS disk space, use the maintenance commands built into lila-docker:
# Check current Docker disk space usage across containers, images, volumes, and build cache
lila-docker df
# Clean up orphaned volumes, dangling images, and BuildKit build cache
lila-docker prune
# Alias for prune (can use -f for non-interactive automated maintenance scripts):
lila-docker clean -f
7. Multi-Project VPS Reverse Proxy (Nginx)
Configure a different PORT and DB_PORT in the .env file for each project.
Nginx can then reverse-proxy traffic to each container:
# Project A .env: PORT=8001, LILA_PROJECT_NAME=shop
# Project B .env: PORT=8002, LILA_PROJECT_NAME=blog
# In Nginx configuration for Shop:
location / {
proxy_pass http://127.0.0.1:8001;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}