๐ How to Deploy a Django Project on cPanel (Step-by-Step Guide)

Deploying a Django project on cPanel is a great way to get your app online without needing a VPS or cloud server. Whether your code is hosted on GitHub or you have the files on your local machine, this step-by-step guide will help you deploy it easily.
๐งฐ Prerequisites
Before starting, make sure you have:
โ A working Django project
โ cPanel account with Python App support
โ Domain or subdomain ready
โ
requirements.txtfile in your projectโ Correct
ALLOWED_HOSTS& production settings
โ๏ธ Step 1: Prepare Your Django Project
Before uploading or cloning:
Collect static files:
python manage.py collectstaticUpdate
ALLOWED_HOSTSinsettings.py:ALLOWED_HOSTS = ['yourdomain.com', 'www.yourdomain.com']Add CSRF trusted origin:
CSRF_TRUSTED_ORIGINS = ['https://yourdomain.com']Set
DEBUG = Falsein production.
๐ Step 2A: Method 1 โ Upload Project Files Directly
Zip your project folder (without
venv).Log in to cPanel.
Open File Manager โ navigate to the folder where you want to host (e.g.,
public_htmlor subdomain).Upload the zip file.
Extract it inside a clean folder like
myproject.
๐ Tip: Keep project files in a separate folder โ donโt mix with other website files.
๐ฅ Step 2B: Method 2 โ Clone Project from GitHub
If your project is on GitHub:
Open cPanel Terminal or SSH Access.
Navigate to your desired directory (e.g.,
public_html):cd public_htmlClone the repo:
git clone https://github.com/yourusername/yourproject.gitRename the folder if needed:
mv yourproject myproject
โ You can also use Gitโข Version Control from the cPanel dashboard if terminal access isnโt available.
๐ Step 3: Create Python App in cPanel
Open โSetup Python Appโ in cPanel.
Click Create Application.
Choose:
Python version: e.g.,
3.10Application Root:
myprojectApplication URL: select your domain/subdomain
Application startup file:
passenger_wsgi.py
Create the app.
This will automatically set up a virtual environment for your project.
๐งช Step 4: Install Dependencies
Open the Terminal from cPanel or click โEnter to virtual environmentโ on the Python App page.
Install requirements:
pip install -r requirements.txt
If you donโt have requirements.txt:
pip freeze > requirements.txt
Then re-upload it or push it to GitHub and install again.
๐ Step 5: Configure passenger_wsgi.py
Inside your project root (e.g., myproject), create or edit passenger_wsgi.py:
import os
import sys
# Add project path
sys.path.insert(0, os.path.dirname(__file__))
os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings'
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
๐ Replace myproject.settings with the actual path of your settings file.
๐งญ Step 6: Collect Static Files on Server
python manage.py collectstatic
Make sure your settings.py contains:
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
This will create a static folder to serve your assets.
๐ข Step 7: (Optional) Configure Database
If youโre using MySQL from cPanel:
Create a database and user in MySQLยฎ Databases.
Update
settings.py:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'yourdbname',
'USER': 'yourdbuser',
'PASSWORD': 'yourdbpassword',
'HOST': 'localhost',
'PORT': '3306',
}
}
- Run migrations:
python manage.py migrate
๐ Step 8: Restart the Python App
Go to โSetup Python Appโ again.
Click Restart App.
Wait a few seconds, then open your domain.
โ Your Django project is now live!
๐ Common Issues & Fixes
| Problem | Reason | Solution |
| 500 Internal Server Error | Wrong WSGI path or missing package | Check passenger_wsgi.py and reinstall requirements |
| Static files not loading | Static not collected | Run collectstatic and ensure STATIC_ROOT is correct |
| Database connection failed | Wrong credentials | Recheck username, password, host, and database name |
| Changes not appearing | App not restarted | Click Restart App after every change |
๐ Extra Tips
โ Use
.envfile or environment variables for sensitive data.๐ก Set correct file permissions (755 for folders, 644 for files).
๐ Always set
DEBUG = Falsein production.๐ Add
www.yourdomain.comandyourdomain.comtoALLOWED_HOSTS.๐งฐ Use Git pull to update your project easily when using GitHub.
๐ Example File Structure
public_html/
โโโ myproject/
โโโ manage.py
โโโ myproject/
โ โโโ settings.py
โ โโโ urls.py
โ โโโ wsgi.py
โโโ passenger_wsgi.py
โโโ requirements.txt
โโโ static/
๐ Conclusion
Deploying a Django project on cPanel is simple once you know the steps.
You can either:
๐ Upload your project manually, or
๐ช Clone it directly from GitHub for easier version control.
With Python App support, cPanel takes care of most server configurations for you. Just make sure your WSGI file, dependencies, and settings are correct โ and your Django app will be online in no time. ๐
โ
Pro Tip: If you plan to maintain and update your project frequently, using GitHub cloning with git pull is much faster and cleaner than manually uploading files every time.





