Requirements (Before You Start)

Make sure your hosting supports:

  • Python (via Setup Python App in cPanel)
  • SSH access (optional but helpful)
  • Passenger (usually enabled by default)

Step 1: Login to cPanel

  • Go to your cPanel (e.g. yourdomain.com/cpanel)
  • Enter your username & password

Step 2: Open “Setup Python App”

  • Search for: Setup Python App
  • Click it

This is where you create and manage your Django app.


Step 3: Create a New Python Application

Click Create Application and fill:

  • Python version → Choose latest available (e.g. 3.10+)
  • Application root → e.g.

     
    myapp
     
  • Application URL

     
    yourdomain.com/
     

    or

     
    yourdomain.com/myapp
     
  • Application startup file

     
    passenger_wsgi.py
     
  • Application Entry point

     
    application
     

Then click Create


Step 4: Activate Virtual Environment

After creation, cPanel will show something like:

 
source /home/username/virtualenv/myapp/3.x/bin/activate
 

Option A: Using Terminal (Recommended)

  • Open Terminal in cPanel or SSH
  • Run:
 
source /home/username/virtualenv/myapp/3.x/bin/activate
 

Step 5: Install Django

Inside the virtual environment:

 
pip install django
 

You can also install your requirements:

 
pip install -r requirements.txt
 

Step 6: Upload Your Django Project

You have 2 options:

Option A: Upload ZIP

  • Go to File Manager
  • Upload your project ZIP
  • Extract inside:
 
/home/username/myapp
 

Option B: Git (Advanced)

 
git clone your-repo-url
 

 Step 7: Configure passenger_wsgi.py

Edit:

 
/home/username/myapp/passenger_wsgi.py
 

Replace with:

 
import sys
import os

# Add your project path
sys.path.insert(0, os.path.dirname(__file__))

# Set Django settings
os.environ['DJANGO_SETTINGS_MODULE'] = 'yourproject.settings'

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

Replace:

 
yourproject
 

with your actual Django project name


Step 8: Configure Django Settings

Open:

 
settings.py
 

Update:

 
ALLOWED_HOSTS = ['yourdomain.com']
 

Static files (important):

 
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
 

Step 9: Run Migrations

In terminal:

 
python manage.py migrate
 

Step 10: Collect Static Files

 
python manage.py collectstatic
 

Type:

 
yes
 

Step 11: Restart Application

Go back to:
Setup Python App → Restart


Step 12: Test Your App

Visit:

 
https://yourdomain.com
 

If everything is correct → ???? Your Django app is live!


Common Fixes (Very Important)

❌ Error: Module Not Found

Run:

 
pip install -r requirements.txt
 

❌ Error: Static Files Not Showing

Make sure:

  • collectstatic was run
  • STATIC_ROOT is correct

❌ Error: 500 Internal Server Error

Check logs:

 
/home/username/logs/
 

Bonus: Use MySQL Database

Instead of SQLite:

  1. Create DB in cPanel → MySQL Databases
  2. Install:
 
pip install mysqlclient
 
  1. Update settings.py

Best Practices (For Production)

  • Turn off debug:
 
DEBUG = False
 
  • Use .env for secrets
  • Secure your app

 

這篇文章有幫助嗎? 0 用戶發現這個有用 (0 投票)