Table of Contents
Setting Up Python Environment
apt install python3-pip python3-venv -y
python3 -m venv /var/www/myapp/venv
source /var/www/myapp/venv/bin/activate
pip install django gunicorn psycopg2-binaryGunicorn WSGI Server
gunicorn --workers 4 --bind 0.0.0.0:8000 myapp.wsgi:applicationNumber of workers: (2 x CPU cores) + 1 is the standard recommendation.
Systemd Service for Auto-restart
[Unit]
Description=gunicorn daemon
[Service]
User=www-data
WorkingDirectory=/var/www/myapp
ExecStart=/var/www/myapp/venv/bin/gunicorn --workers 4 --bind unix:/var/www/myapp/myapp.sock myapp.wsgi:application
[Install]
WantedBy=multi-user.targetFAQ
Django vs Flask — which is better for production?
Django is a batteries-included framework ideal for complex applications. Flask is minimalist and flexible, better for APIs and smaller services. Both are production-proven at massive scale.
Ready to deploy?
Host Python Apps on NVMe VPS
Optimized VPS for Django, Flask, and FastAPI applications with dedicated vCores.
