🚀 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
          

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/your_project/start_lila.sh

                        

5. Disable Debug Mode

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

.env
 
DEBUG=False
                        

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.