Special Sale
StableCluster Logo

How to deploy a Django application on cPanel?

An easy guide to deploy your Django Application in cPanel. Step wise guide to deploy your Node.js Application in just 10 steps.
Dec 30, 2024Saurav Bista3 minutes read

How to deploy Django Application in cPanel?

So you are a Python developer who doesn’t know how to deploy Django Applications on cPanel? Well, this guide is all you need for an easier deployment. This detailed step-wise guide starts with the basics for a smooth Django application deployment. Deploying a Django application using cPanel is a must-have skill for all web developers. So, lets learn how:

Before You Begin

Before we start the deployment process, here’s a small checklist for a smooth installation process.

  • A Django application/project ready for deployment.
  • A well-set-up domain name
  • A code editor like Visual Studio Code
  • Basic Knowledge of Python and Django
  • Access to your cPanel credentials
  • FTP client (if you decide to file transfer using FTP client)

Step-by-Step Deployment Guide for your Django Project.

Step 1: Install Django Framework on cPanel

Log in to your cPanel account with your credentials. Navigate to the “Setup Python App” section and click the “Create Application” button.

Now configure your Python application as

  1. Log into your cPanel account.

cpanel-login

2. Navigate to the “Software” section and click the Setup Python App feature.

Django-setup

3. Click the “Create Application” button

application-dashboard

4. Configure your Python application:

    • Select your Python version (recommended: Python 3.8 or higher)
    • Specify the Application root folder name
    • Enter your Application hostname (URL)
    • Click “Create.”

mcg-test

5. Open the provided URL to verify the initial setup.(Blue open text beside the Application URL section)

6. You should see a success message displayed that signals Python is configured in your cPanel

success

 

Step 2: Set Up Virtual Environment

Locate the virtual environment code in your Python application and copy it.

  1. Open the terminal in your cPanel
  2. Paste the activation code and press Entervirtual-environment-codevirtual-code-run
  3. Run pip install django in the terminal.pip-install-django
  4. Run django-admin start project project in the terminaldjango-startproject

Step 3: Verify Installation

Now, to verify the installation, follow these steps:

  1. Navigate to File Manager and then to a folder named “virtualenv”
  2. Open the virtual folder and look for your python version. In my case, Python version 3.8 is displayed.
  3. Inside the “bin” folder, you can find all the required dependencies installed.verfiy-installation

You have successfully installed the Python Django framework on your c-panel.

Step 4: Prepare Your Application

It’s now time to prepare your application for deployment.

  1. Open your Django project in the code editor, preferably Visual Studio Code.
  2. Navigate to the root directory
  3. Run pip freeze>requirements.txt (This creates a requirement.txt file inside the Django applicationpip freeze
  4. Open the requirements.txt file to see all your project dependencies here.
  5. Now, create a zip file of your projectcompress

Necessary: Do not include the env folder

Step 5: Upload and Configure

  1. Go to cPanel File Manager
  2. Navigate to your application root folder
  3. Upload your ZIP file hereupload
  4. Extract the ZIP file in the same folder
  5. Now, open the passenger_wsgi.py file
  6. You can make changes to the passenger_wsgi.py file depending on your paths and project name.passenger-wsgi.py file

 

Step 6: Configure Django Settings

Configure your Django Settings by adding your hostname and root files.

  1. Open your project and navigate to the settings.py file
  2. Edit this file to add your hostname to ALLOWED HOST and root for static/media files.allowed hostroots
  3. You can also update the database configurations if needed

Step 7: Install Dependencies and Finalize

Installing dependencies is the final step to deploy your Django application

  1. Return back to the cPanel terminal
  2. Activate the virtual environment copying the code snippet and running it in the terminal
  3. Run: pip install -r requirements.txtrequirements
  4. Once your dependencies are successfully installed, run python manage.py collectstaticpython manage
  5. Answer “yes” when prompted

Step 8: Launch Your Application

  1. Go back to the Python App section in cPanel
  2. Click “Restart Application”
  3. Visit your application URLproject
  4. Congratulations! Your Django application should now be live

Common Issues and Solutions

Application Won’t Start

  • Check application logs in cPanel
  • Verify that all passenger_wsgi.py settings are as needed
  • Confirm all dependencies required are installed
  • Check Python version compatibility
  • Look for path configuration issues

Static Files Not Loading

  • Verify static file configuration
  • Run collect static again
  • Check file permissions
  • Confirm static file path

Database Connection Issues

  • Review database credentials
  • Check database configuration
  • Ensure the database is running
  • Verify migration status

Best Practices

Security Measures

  • Keep DEBUG mode off in production
  • Use strong passwords
  • Install SSL certificate
  • Regular security updates
  • Protect sensitive files

Maintenance Tasks

  • Regular database backups
  • Monitor error logs
  • Update dependencies
  • Document changes you make
  • Regular performance checks

Performance Tips

  • Enable caching
  • Optimize database
  • Compress static files
  • Monitor resources
  • Regular cleanup

Final Tips

  1. Document your deployment process for future reference
  2. Set up monitoring for your application performance
  3. Keep dependencies updated
  4. Check logs regularly
  5. Test thoroughly before deploying
  6. Use version control
  7. Monitor server resources

This guide provides everything needed to deploy your Django application on cPanel. Before going live with your production deployment, remember to test in a staging environment.

 

50% OFF

🌟 It’s the last chance to grab an exciting offer from StableCluster.

with the discount code

NEWYEAR2025

Share This Article


Copy to clipboard
Saurav Bista
Saurav Bista

Saurav is a seasoned content writer at StableCluster with a strong foundation in Information Systems and over four years of experience in creating impactful, insightful content. Combining his passion for writing and technology, he excels at crafting narratives that deeply connect with readers, inspiring confidence and guiding them through the complexities of the digital landscape.