Skip to main content

To deploy a Flask or Django Python application live on Hostinger, set up a Hostinger KVM VPS running Ubuntu, connect via SSH, and build an isolated Python virtual environment for your application code. Next, configure Gunicorn as the WSGI application server managed by a systemd background service, route incoming HTTP traffic through an Nginx reverse proxy, and protect your domain with a free SSL certificate.

How to deploy a Flask or Django Python app live on Hostinger

Deploying Python Web Applications on Hostinger: The Ultimate Guide

Python frameworks like Django and Flask power everything from lightweight microservices and AI utility wrappers to full-fledged SaaS applications and enterprise platforms. However, taking a locally developed Python app and publishing it live to a global production environment can feel daunting for many developers.

Hostinger provides an ideal, high-performance infrastructure for running Python applications. Thanks to its NVMe SSD storage, dedicated KVM virtualization, automated setup templates, and full root SSH access, Hostinger delivers enterprise-grade hosting at a fraction of traditional server costs.

Whether you are building a lightweight API in Flask or deploying a battery-included web platform in Django, this step-by-step guide will walk you through the full deployment pipeline on Hostinger.

Why Hostinger is Ideal for Students, Freelancers, and Developers

Before diving into the technical setup, it is worth understanding why Hostinger is a top choice among modern Python developers:

  • For Computer Science & Bootcamp Students: Hostinger’s VPS environment gives you hands-on experience with real Linux production servers, Nginx configurations, virtual environments, and SSH management without complex cloud billing structures.

  • For Freelancers & Web Agencies: Delivering client projects on Hostinger guarantees high uptime, low latency, and easily scalable CPU/RAM upgrades as client traffic grows—allowing you to offer high-value web hosting packages.

  • For Full-Stack & Backend Developers: Full root access enables complete freedom to install custom database engines (PostgreSQL, MySQL, Redis), background job queues (Celery), and specific Python runtime dependencies.

Prerequisites Before Deployment

To ensure a smooth live deployment, gather the following before starting:

  1. A completed Django or Flask application running locally.

  2. A GitHub or GitLab repository containing your project source code.

  3. A requirements.txt file listing all required Python libraries.

  4. A registered domain name mapped to your target server IP address.

  5. A Hostinger KVM VPS Hosting Plan (Ubuntu 22.04 or 24.04 LTS recommended).

Step 1: Provision Your Hostinger VPS Server

  1. Log into your Hostinger hPanel dashboard.

  2. Navigate to VPS Setup and select Ubuntu LTS as your operating system.

  3. Set up a secure SSH password and copy your server’s dedicated IP address.

  4. Open your terminal (macOS/Linux) or Command Prompt/PuTTY (Windows) and log into your server as root:

Bash

ssh root@YOUR_SERVER_IP
  1. Update system packages to ensure your server has the latest security patches:

Bash

sudo apt update && sudo apt upgrade -y

Step 2: Install Python, Dependencies, and Nginx

Install Python 3, pip, venv (virtual environment manager), Git, and Nginx web server:

Bash

sudo apt install python3-pip python3-venv python3-dev nginx git curl -y

Verify that Python and Nginx are installed correctly:

Bash

python3 --version
nginx -v

Step 3: Clone Your Codebase and Set Up Virtual Environment

  1. Navigate to the web directory and clone your application code from GitHub:

Bash

cd /var/www
sudo git clone https://github.com/your-username/your-python-repo.git app
cd app
  1. Create an isolated Python virtual environment to keep global system packages clean:

Bash

python3 -m venv venv
source venv/bin/activate
  1. Upgrade pip and install your application dependencies:

Bash

pip install --upgrade pip
pip install -r requirements.txt
pip install gunicorn

Step 4: Configure Application Production Settings

For Django Projects:

  1. Open your project settings file (settings.py):

    Python

    DEBUG = False
    ALLOWED_HOSTS = ['yourdomain.com', 'www.yourdomain.com', 'YOUR_SERVER_IP']
    STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
    
  2. Collect static files and execute database migrations:

    Bash

    python manage.py collectstatic --noinput
    python manage.py migrate
    

For Flask Projects:

Ensure your core file (e.g., app.py or wsgi.py) exposes the Flask instance correctly:

Python

from myapp import app

if __name__ == "__main__":
    app.run()

Step 5: Configure Gunicorn and Systemd Service

To keep your Flask or Django app running continuously in the background—even after server reboots—create a Systemd service file.

  1. Create a systemd socket service:

Bash

sudo nano /etc/systemd/system/gunicorn.service
  1. Add the following service configuration (replace app with your folder name and adjust WSGI paths accordingly):

Ini, TOML

[Unit]
Description=Gunicorn daemon for Python Web Application
After=network.target

[Service]
User=root
Group=www-data
WorkingDirectory=/var/www/app
ExecStart=/var/www/app/venv/bin/gunicorn --workers 3 --bind unix:/var/www/app/app.sock wsgi:app

[Install]
WantedBy=multi-user.target
  1. Enable and start the Gunicorn service:

Bash

sudo systemctl daemon-reload
sudo systemctl start gunicorn
sudo systemctl enable gunicorn

Verify that the socket was created successfully:

Bash

sudo systemctl status gunicorn

Step 6: Configure Nginx as Reverse Proxy

Nginx will receive web requests on HTTP port 80 and forward them to Gunicorn through the Unix socket.

  1. Create a new Nginx configuration file:

Bash

sudo nano /etc/nginx/sites-available/app
  1. Paste the following configuration block (update yourdomain.com with your actual domain):

Nginx

server {
    listen 80;
    server_name yourdomain.com www.yourdomain.com YOUR_SERVER_IP;

    location /static/ {
        alias /var/www/app/staticfiles/;
    }

    location / {
        include proxy_params;
        proxy_pass http://unix:/var/www/app/app.sock;
    }
}
  1. Enable the configuration and test for syntax errors:

Bash

sudo ln -s /etc/nginx/sites-available/app /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl restart nginx

Step 7: Secure Domain with Free SSL (Certbot)

To protect user data with HTTPS encryption, install Certbot and issue a free Let’s Encrypt SSL certificate:

Bash

sudo apt install snapd -y
sudo snap install --classic certbot
sudo ln -s /snap/bin/certbot /usr/bin/certbot
sudo certbot --nginx -d yourdomain.com -d www.yourdomain.com

Certbot will automatically configure your Nginx server block to redirect HTTP traffic securely to HTTPS.

Performance Optimization & Maintenance Checklist

To maintain maximum application speed and uptime:

  • Enable UFW Firewall: Allow SSH, HTTP, and HTTPS traffic (sudo ufw allow 'Nginx Full' && sudo ufw enable).

  • Environment Variables: Store confidential keys (SECRET_KEY, database credentials) inside a .env file rather than committing them to Git.

  • Log Monitoring: Inspect live logs whenever troubleshooting issues:

    • Gunicorn logs: sudo journalctl -u gunicorn

    • Nginx access logs: sudo tail -f /var/log/nginx/access.log

    • Nginx error logs: sudo tail -f /var/log/nginx/error.log

Claim Exclusive Hostinger Hosting Discount

Ready to deploy your Flask or Django web application live to the world? Hostinger provides ultra-fast NVMe storage, dedicated KVM VPS resources, top-tier global data centers, and 24/7 technical support—making it the ultimate home for your Python apps.

Take advantage of an EXCLUSIVE 20% EXTRA DISCOUNT on your hosting plan today.

How to Redeem Your Discount:

  1. Click the button below to visit the official Hostinger portal.

  2. Select your preferred KVM VPS or Web Hosting package.

  3. The promotional referral code Meerub will apply automatically at checkout to maximize your savings.

Get 20% OFF Hostinger VPS – Deploy Your App Now

TM

Leave a Reply