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

Search for a command to run...

No comments yet. Be the first to comment.
Ensuring your website is secure is crucial, especially if it involves sensitive data exchanges or user authentication. Moving from HTTP to HTTPS not only improves the trustworthiness of your website but also ensures it meets the best security standar...

Introduction Django is a robust web framework designed to help you rapidly build Python applications or websites. While Django provides a simplified local development server, youโll need a more secure and scalable server setup for production environm...

Creating documentation for a Flutter project involves several key components. Hereโs a step-by-step guide to help you through the process: 1. Project Overview Project Name: Include the name of your Flutter project. Introduction: Provide a brief des...

Creating an e-commerce app in Flutter can be a rewarding experience, especially with Flutter's powerful toolkit that enables the development of high-quality cross-platform mobile applications. Whether youโre a beginner or an experienced developer, th...

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.
Before starting, make sure you have:
โ A working Django project
โ cPanel account with Python App support
โ Domain or subdomain ready
โ
requirements.txt file in your project
โ
Correct ALLOWED_HOSTS & production settings
Before uploading or cloning:
Collect static files:
python manage.py collectstatic
Update ALLOWED_HOSTS in settings.py:
ALLOWED_HOSTS = ['yourdomain.com', 'www.yourdomain.com']
Add CSRF trusted origin:
CSRF_TRUSTED_ORIGINS = ['https://yourdomain.com']
Set DEBUG = False in production.
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_html or 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.
If your project is on GitHub:
Open cPanel Terminal or SSH Access.
Navigate to your desired directory (e.g., public_html):
cd public_html
Clone the repo:
git clone https://github.com/yourusername/yourproject.git
Rename the folder if needed:
mv yourproject myproject
โ You can also use Gitโข Version Control from the cPanel dashboard if terminal access isnโt available.
Open โSetup Python Appโ in cPanel.
Click Create Application.
Choose:
Python version: e.g., 3.10
Application Root: myproject
Application 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.
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.
passenger_wsgi.pyInside 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.
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.
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',
}
}
python manage.py migrate
Go to โSetup Python Appโ again.
Click Restart App.
Wait a few seconds, then open your domain.
โ Your Django project is now live!
| 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 |
โ
Use .env file or environment variables for sensitive data.
๐ก Set correct file permissions (755 for folders, 644 for files).
๐ Always set DEBUG = False in production.
๐ Add www.yourdomain.com and yourdomain.com to ALLOWED_HOSTS.
๐งฐ Use Git pull to update your project easily when using GitHub.
public_html/
โโโ myproject/
โโโ manage.py
โโโ myproject/
โ โโโ settings.py
โ โโโ urls.py
โ โโโ wsgi.py
โโโ passenger_wsgi.py
โโโ requirements.txt
โโโ static/
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.