How to Deploy a Django App with PostgreSQL on cPanel: A Beginner's Guide

How to Deploy a Django App with PostgreSQL on cPanel: A Beginner's Guide

Deploying a Django application on cPanel shared hosting may look confusing at first, especially when PostgreSQL and Python virtual environments are involved.
This guide walks you through each step slowly and clearly, assuming you are a beginner.

We’ll deploy a Django project named mysite on the domain:

bhandarisudip.com.np

What You Need Before Starting

Make sure your Django project includes:

  • manage.py

  • requirements.txt

  • A project folder (mysite/) containing:

    • settings.py

    • wsgi.py

  • PostgreSQL support (psycopg2-binary in requirements)

You also need:

  • cPanel hosting with Python App (Passenger) enabled

  • A domain already pointing to your hosting server


Step 1: SSH Setup & Project Cloning

First, enable SSH access in cPanel and connect to your server.

Once SSH is ready, clone your project:

cd /home/USERNAME
git clone YOUR_REPOSITORY_URL mysite

If you don’t use Git, you can upload your project as a ZIP file using cPanel → File Manager and extract it.


Step 2: Add Domain in cPanel

Go to cPanel → Domains

  • Add domain:
    bhandarisudip.com.np

  • Set document root (recommended):

/home/USERNAME/bhandarisudip

✅ Your Django project (mysite) does not need to be inside public_html.


Step 3: Upload Project to File Manager (if not cloned)

Open cPanel → File Manager
Upload your Django project to:

/home/USERNAME/mysite

Confirm these files exist:

  • manage.py

  • mysite/settings.py

  • mysite/wsgi.py


Step 4: Create PostgreSQL Database

Go to cPanel → PostgreSQL Databases

  1. Create database:
USERNAME_mysite_db
  1. Create user:
USERNAME_mysite_user
  1. Assign user to database with ALL PRIVILEGES

Save these details carefully:

  • Database name

  • Username

  • Password

  • Host: localhost

  • Port: 5432


Step 5: Create Python App (cPanel)

Go to cPanel → Setup Python App → Create Application

Fill in:

SettingValue
Python version3.10 or 3.11
Application root/home/USERNAME/mysite
Application URLbhandarisudip.com.np
Startup filepassenger_wsgi.py
Entry pointapplication

Click Create.


Step 6: Install Project Dependencies

Open Terminal / SSH:

cd /home/USERNAME/mysite
source /home/USERNAME/virtualenv/mysite/3.11/bin/activate
pip install --upgrade pip
pip install -r requirements.txt

If PostgreSQL driver is missing:

pip install psycopg2-binary

Step 7: Update Django Settings for Production

A) ALLOWED_HOSTS

In settings.py:

ALLOWED_HOSTS = [
    "bhandarisudip.com.np",
    "www.bhandarisudip.com.np"
]

B) PostgreSQL Database Configuration

DATABASES = {
    "default": {
        "ENGINE": "django.db.backends.postgresql",
        "NAME": "USERNAME_mysite_db",
        "USER": "USERNAME_mysite_user",
        "PASSWORD": "DB_PASSWORD",
        "HOST": "localhost",
        "PORT": "5432",
    }
}

C) Static & Media Settings

STATIC_URL = "/static/"
STATIC_ROOT = BASE_DIR / "staticfiles"

MEDIA_URL = "/media/"
MEDIA_ROOT = BASE_DIR / "media"

Step 8: Create passenger_wsgi.py

Inside /home/USERNAME/mysite/, create:

import os
import sys

PROJECT_PATH = "/home/USERNAME/mysite"
if PROJECT_PATH not in sys.path:
    sys.path.insert(0, PROJECT_PATH)

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

Step 9: Run Migrations & Collect Static Files

cd /home/USERNAME/mysite
source /home/USERNAME/virtualenv/mysite/3.11/bin/activate

python manage.py migrate
python manage.py collectstatic

Step 10: Set Permissions for Static & Media Files

chmod -R 755 /home/USERNAME/mysite/staticfiles
chmod -R 755 /home/USERNAME/mysite/media

If folders don’t exist:

mkdir -p /home/USERNAME/mysite/staticfiles
mkdir -p /home/USERNAME/mysite/media

Assuming domain root:

/home/USERNAME/bhandarisudip

Create symlinks:

ln -s /home/USERNAME/mysite/staticfiles /home/USERNAME/bhandarisudip/static
ln -s /home/USERNAME/mysite/media /home/USERNAME/bhandarisudip/media

Step 12: Restart the Python App

In Setup Python App, click Restart

OR via SSH:

mkdir -p /home/USERNAME/mysite/tmp
touch /home/USERNAME/mysite/tmp/restart.txt

Common Errors & Fixes

ProblemSolution
500 Internal Server ErrorCheck passenger_wsgi.py and ALLOWED_HOSTS
Database connection errorVerify DB prefix & password
Static files not loadingRun collectstatic and check symlinks
Changes not showingRestart Python app

✅ Deployment Complete

Your Django application is now live on:

👉 https://bhandarisudip.com.np