Skip to main content

Command Palette

Search for a command to run...

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

Updated
โ€ข4 min read
๐Ÿš€ 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.txt file in your project

  • โœ… Correct ALLOWED_HOSTS & production settings


โš™๏ธ Step 1: Prepare Your Django Project

Before uploading or cloning:

  1. Collect static files:

     python manage.py collectstatic
    
  2. Update ALLOWED_HOSTS in settings.py:

     ALLOWED_HOSTS = ['yourdomain.com', 'www.yourdomain.com']
    
  3. Add CSRF trusted origin:

     CSRF_TRUSTED_ORIGINS = ['https://yourdomain.com']
    
  4. Set DEBUG = False in production.


๐Ÿ“ Step 2A: Method 1 โ€“ Upload Project Files Directly

  1. Zip your project folder (without venv).

  2. Log in to cPanel.

  3. Open File Manager โ†’ navigate to the folder where you want to host (e.g., public_html or subdomain).

  4. Upload the zip file.

  5. 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:

  1. Open cPanel Terminal or SSH Access.

  2. Navigate to your desired directory (e.g., public_html):

     cd public_html
    
  3. Clone the repo:

     git clone https://github.com/yourusername/yourproject.git
    
  4. 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.


๐ŸŒ Step 3: Create Python App in cPanel

  1. Open โ€œSetup Python Appโ€ in cPanel.

  2. Click Create Application.

  3. Choose:

    • Python version: e.g., 3.10

    • Application Root: myproject

    • Application URL: select your domain/subdomain

    • Application startup file: passenger_wsgi.py

  4. 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:

  1. Create a database and user in MySQLยฎ Databases.

  2. Update settings.py:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'yourdbname',
        'USER': 'yourdbuser',
        'PASSWORD': 'yourdbpassword',
        'HOST': 'localhost',
        'PORT': '3306',
    }
}
  1. 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

ProblemReasonSolution
500 Internal Server ErrorWrong WSGI path or missing packageCheck passenger_wsgi.py and reinstall requirements
Static files not loadingStatic not collectedRun collectstatic and ensure STATIC_ROOT is correct
Database connection failedWrong credentialsRecheck username, password, host, and database name
Changes not appearingApp not restartedClick Restart App after every change

๐ŸŒŸ Extra Tips

  • โœ… 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.


๐Ÿ“ 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.

More from this blog