Apply for Free VPS

Deploy a Python web application

Updated 27 Nov 2026 python gunicorn

Run Django or Flask with a virtual environment, Gunicorn and systemd.

Install

sudo apt update
sudo apt install -y python3-venv python3-pip git nginx
sudo adduser --system --group --home /srv/app app
sudo git clone https://example.com/your/repo.git /srv/app/current
sudo chown -R app:app /srv/app

Virtual environment

cd /srv/app/current
sudo -u app python3 -m venv .venv
sudo -u app .venv/bin/pip install -r requirements.txt gunicorn

Service

/etc/systemd/system/app.service:

[Service]
User=app
WorkingDirectory=/srv/app/current
EnvironmentFile=/etc/app.env
ExecStart=/srv/app/current/.venv/bin/gunicorn --bind 127.0.0.1:8000 --workers 2 myproject.wsgi:application
Restart=on-failure

[Install]
WantedBy=multi-user.target

For Flask, replace the last argument with app:app. Keep secrets in /etc/app.env with mode 600.

sudo systemctl daemon-reload && sudo systemctl enable --now app

Django settings

Set DEBUG = False, fill ALLOWED_HOSTS, then run migrate and collectstatic. Serve static files with Nginx.

Workers

Start with two on a one-vCPU server and watch memory.

Was this helpful?

Report outdated or incorrect information